testbench

package
v0.0.0-...-ba09d25 Latest Latest
Warning

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

Go to latest
Published: Dec 29, 2021 License: Apache-2.0, MIT Imports: 27 Imported by: 0

Documentation

Overview

Package testbench has utilities to send and receive packets, and also command the DUT to run POSIX functions. It is the packetimpact test API.

Index

Constants

This section is empty.

Variables

View Source
var (
	// Native indicates that the test is being run natively.
	Native = false
	// RPCKeepalive is the gRPC keepalive.
	RPCKeepalive = 10 * time.Second
)

Functions

func Address

func Address(v tcpip.Address) *tcpip.Address

Address is a helper routine that allocates a new tcpip.Address value to store v and returns a pointer to it.

func Bool

func Bool(v bool) *bool

Bool is a helper routine that allocates a new bool value to store v and returns a pointer to it.

func GenerateRandomPayload

func GenerateRandomPayload(t *testing.T, n int) []byte

GenerateRandomPayload generates a random byte slice of the specified length, causing a fatal test failure if it is unable to do so.

func ICMPv4Code

func ICMPv4Code(t header.ICMPv4Code) *header.ICMPv4Code

ICMPv4Code is a helper routine that allocates a new header.ICMPv4Code value to store t and returns a pointer to it.

func ICMPv4Type

func ICMPv4Type(t header.ICMPv4Type) *header.ICMPv4Type

ICMPv4Type is a helper routine that allocates a new header.ICMPv4Type value to store t and returns a pointer to it.

func ICMPv6Code

func ICMPv6Code(v header.ICMPv6Code) *header.ICMPv6Code

ICMPv6Code is a helper routine that allocates a new ICMPv6Type value to store v and returns a pointer to it.

func ICMPv6Type

func ICMPv6Type(v header.ICMPv6Type) *header.ICMPv6Type

ICMPv6Type is a helper routine that allocates a new ICMPv6Type value to store v and returns a pointer to it.

func IPv6ExtHdrIdent

IPv6ExtHdrIdent is a helper routine that allocates a new header.IPv6ExtensionHeaderIdentifier value to store v and returns a pointer to it.

func Initialize

func Initialize(fs *flag.FlagSet)

Initialize initializes the testbench, it parse the flags and sets up the pool of test networks for testbench's later use.

func LinkAddress

func LinkAddress(v tcpip.LinkAddress) *tcpip.LinkAddress

LinkAddress is a helper routine that allocates a new tcpip.LinkAddress value to store v and returns a pointer to it.

func NetworkProtocolNumber

func NetworkProtocolNumber(v tcpip.NetworkProtocolNumber) *tcpip.NetworkProtocolNumber

NetworkProtocolNumber is a helper routine that allocates a new tcpip.NetworkProtocolNumber value to store v and returns a pointer to it.

func SeqNumValue

func SeqNumValue(v seqnum.Value) *seqnum.Value

SeqNumValue is a helper routine that allocates a new seqnum.Value value to store v and returns a pointer to it.

func TCPFlags

func TCPFlags(v header.TCPFlags) *header.TCPFlags

TCPFlags is a helper routine that allocates a new header.TCPFlags value to store v and returns a pointer to it.

func Uint16

func Uint16(v uint16) *uint16

Uint16 is a helper routine that allocates a new uint16 value to store v and returns a pointer to it.

func Uint32

func Uint32(v uint32) *uint32

Uint32 is a helper routine that allocates a new uint32 value to store v and returns a pointer to it.

func Uint8

func Uint8(v uint8) *uint8

Uint8 is a helper routine that allocates a new uint8 value to store v and returns a pointer to it.

Types

type Connection

type Connection struct {
	// contains filtered or unexported fields
}

Connection holds a collection of layer states for maintaining a connection along with sockets for sniffer and injecting packets.

func (*Connection) Close

func (conn *Connection) Close(t *testing.T)

Close frees associated resources held by the Connection.

func (*Connection) CreateFrame

func (conn *Connection) CreateFrame(t *testing.T, overrideLayers Layers, additionalLayers ...Layer) Layers

CreateFrame builds a frame for the connection with defaults overridden from the innermost layer out, and additionalLayers added after it.

Note that overrideLayers can have a length that is less than the number of layers in this connection, and in such cases the innermost layers are overridden first. As an example, valid values of overrideLayers for a TCP- over-IPv4-over-Ethernet connection are: nil, TCP, [IPv4, TCP], and [Ethernet, IPv4, TCP].

func (*Connection) Drain

func (conn *Connection) Drain(t *testing.T)

Drain drains the sniffer's receive buffer by receiving packets until there's nothing else to receive.

func (*Connection) Expect

func (conn *Connection) Expect(t *testing.T, layer Layer, timeout time.Duration) (Layer, error)

Expect expects a frame with the final layerStates layer matching the provided Layer within the timeout specified. If it doesn't arrive in time, an error is returned.

func (*Connection) ExpectFrame

func (conn *Connection) ExpectFrame(t *testing.T, layers Layers, timeout time.Duration) (Layers, error)

ExpectFrame expects a frame that matches the provided Layers within the timeout specified. If one arrives in time, the Layers is returned without an error. If it doesn't arrive in time, it returns nil and error is non-nil.

func (*Connection) ListenForFrame

func (conn *Connection) ListenForFrame(t *testing.T, layers Layers, timeout time.Duration) ([]Layers, bool)

ListenForFrame captures all frames until a frame matches the provided Layers, or until the timeout specified. Returns all captured frames, including the matched frame, and true if the desired frame was found.

func (*Connection) SendFrame

func (conn *Connection) SendFrame(t *testing.T, frame Layers)

SendFrame sends a frame on the wire and updates the state of all layers.

func (*Connection) SendFrameStateless

func (conn *Connection) SendFrameStateless(t *testing.T, frame Layers)

SendFrameStateless sends a frame without updating any of the layer states.

This method is useful for sending out-of-band control messages such as ICMP packets, where it would not make sense to update the transport layer's state using the ICMP header.

type DUT

type DUT struct {
	Net   *DUTTestNet
	Uname *DUTUname
	// contains filtered or unexported fields
}

DUT communicates with the DUT to force it to make POSIX calls.

func NewDUT

func NewDUT(t *testing.T) DUT

NewDUT creates a new connection with the DUT over gRPC.

func (*DUT) Accept

func (dut *DUT) Accept(t *testing.T, sockfd int32) (int32, unix.Sockaddr)

Accept calls accept on the DUT and causes a fatal test failure if it doesn't succeed. If more control over the timeout or error handling is needed, use AcceptWithErrno.

func (*DUT) AcceptWithErrno

func (dut *DUT) AcceptWithErrno(ctx context.Context, t *testing.T, sockfd int32) (int32, unix.Sockaddr, error)

AcceptWithErrno calls accept on the DUT.

func (*DUT) Bind

func (dut *DUT) Bind(t *testing.T, fd int32, sa unix.Sockaddr)

Bind calls bind on the DUT and causes a fatal test failure if it doesn't succeed. If more control over the timeout or error handling is needed, use BindWithErrno.

func (*DUT) BindWithErrno

func (dut *DUT) BindWithErrno(ctx context.Context, t *testing.T, fd int32, sa unix.Sockaddr) (int32, error)

BindWithErrno calls bind on the DUT.

func (*DUT) Close

func (dut *DUT) Close(t *testing.T, fd int32)

Close calls close on the DUT and causes a fatal test failure if it doesn't succeed. If more control over the timeout or error handling is needed, use CloseWithErrno.

func (*DUT) CloseWithErrno

func (dut *DUT) CloseWithErrno(ctx context.Context, t *testing.T, fd int32) (int32, error)

CloseWithErrno calls close on the DUT.

func (*DUT) Connect

func (dut *DUT) Connect(t *testing.T, fd int32, sa unix.Sockaddr)

Connect calls connect on the DUT and causes a fatal test failure if it doesn't succeed. If more control over the timeout or error handling is needed, use ConnectWithErrno.

func (*DUT) ConnectWithErrno

func (dut *DUT) ConnectWithErrno(ctx context.Context, t *testing.T, fd int32, sa unix.Sockaddr) (int32, error)

ConnectWithErrno calls bind on the DUT.

func (*DUT) CreateBoundSocket

func (dut *DUT) CreateBoundSocket(t *testing.T, typ, proto int32, addr net.IP) (int32, uint16)

CreateBoundSocket makes a new socket on the DUT, with type typ and protocol proto, and bound to the IP address addr. Returns the new file descriptor and the port that was selected on the DUT.

func (*DUT) CreateListener

func (dut *DUT) CreateListener(t *testing.T, typ, proto, backlog int32) (int32, uint16)

CreateListener makes a new TCP connection. If it fails, the test ends.

func (*DUT) GetSockName

func (dut *DUT) GetSockName(t *testing.T, sockfd int32) unix.Sockaddr

GetSockName calls getsockname on the DUT and causes a fatal test failure if it doesn't succeed. If more control over the timeout or error handling is needed, use GetSockNameWithErrno.

func (*DUT) GetSockNameWithErrno

func (dut *DUT) GetSockNameWithErrno(ctx context.Context, t *testing.T, sockfd int32) (int32, unix.Sockaddr, error)

GetSockNameWithErrno calls getsockname on the DUT.

func (*DUT) GetSockOpt

func (dut *DUT) GetSockOpt(t *testing.T, sockfd, level, optname, optlen int32) []byte

GetSockOpt calls getsockopt on the DUT and causes a fatal test failure if it doesn't succeed. If more control over the timeout or error handling is needed, use GetSockOptWithErrno. Because endianess and the width of values might differ between the testbench and DUT architectures, prefer to use a more specific GetSockOptXxx function.

func (*DUT) GetSockOptInt

func (dut *DUT) GetSockOptInt(t *testing.T, sockfd, level, optname int32) int32

GetSockOptInt calls getsockopt on the DUT and causes a fatal test failure if it doesn't succeed. If more control over the int optval or error handling is needed, use GetSockOptIntWithErrno.

func (*DUT) GetSockOptIntWithErrno

func (dut *DUT) GetSockOptIntWithErrno(ctx context.Context, t *testing.T, sockfd, level, optname int32) (int32, int32, error)

GetSockOptIntWithErrno calls getsockopt with an integer optval.

func (*DUT) GetSockOptTCPInfo

func (dut *DUT) GetSockOptTCPInfo(t *testing.T, sockfd int32) linux.TCPInfo

GetSockOptTCPInfo retreives TCPInfo for the given socket descriptor.

func (*DUT) GetSockOptTCPInfoWithErrno

func (dut *DUT) GetSockOptTCPInfoWithErrno(ctx context.Context, t *testing.T, sockfd int32) (int32, linux.TCPInfo, error)

GetSockOptTCPInfoWithErrno retreives TCPInfo with any errno.

func (*DUT) GetSockOptTimeval

func (dut *DUT) GetSockOptTimeval(t *testing.T, sockfd, level, optname int32) unix.Timeval

GetSockOptTimeval calls getsockopt on the DUT and causes a fatal test failure if it doesn't succeed. If more control over the timeout or error handling is needed, use GetSockOptTimevalWithErrno.

func (*DUT) GetSockOptTimevalWithErrno

func (dut *DUT) GetSockOptTimevalWithErrno(ctx context.Context, t *testing.T, sockfd, level, optname int32) (int32, unix.Timeval, error)

GetSockOptTimevalWithErrno calls getsockopt and returns a timeval.

func (*DUT) GetSockOptWithErrno

func (dut *DUT) GetSockOptWithErrno(ctx context.Context, t *testing.T, sockfd, level, optname, optlen int32) (int32, []byte, error)

GetSockOptWithErrno calls getsockopt on the DUT. Because endianess and the width of values might differ between the testbench and DUT architectures, prefer to use a more specific GetSockOptXxxWithErrno function.

func (*DUT) Listen

func (dut *DUT) Listen(t *testing.T, sockfd, backlog int32)

Listen calls listen on the DUT and causes a fatal test failure if it doesn't succeed. If more control over the timeout or error handling is needed, use ListenWithErrno.

func (*DUT) ListenWithErrno

func (dut *DUT) ListenWithErrno(ctx context.Context, t *testing.T, sockfd, backlog int32) (int32, error)

ListenWithErrno calls listen on the DUT.

func (*DUT) Poll

func (dut *DUT) Poll(t *testing.T, pfds []unix.PollFd, timeout time.Duration) []unix.PollFd

Poll calls poll on the DUT and causes a fatal test failure if it doesn't succeed. If more control over error handling is needed, use PollWithErrno. Only pollfds with non-empty revents are returned, the only way to tie the response back to the original request is using the fd number.

func (*DUT) PollOne

func (dut *DUT) PollOne(t *testing.T, fd int32, events int16, timeout time.Duration)

PollOne calls poll on the DUT and asserts that the expected event must be signaled on the given fd within the given timeout.

func (*DUT) PollWithErrno

func (dut *DUT) PollWithErrno(ctx context.Context, t *testing.T, pfds []unix.PollFd, timeout time.Duration) (int32, []unix.PollFd, error)

PollWithErrno calls poll on the DUT.

func (*DUT) Recv

func (dut *DUT) Recv(t *testing.T, sockfd, len, flags int32) []byte

Recv calls recv on the DUT and causes a fatal test failure if it doesn't succeed. If more control over the timeout or error handling is needed, use RecvWithErrno.

func (*DUT) RecvWithErrno

func (dut *DUT) RecvWithErrno(ctx context.Context, t *testing.T, sockfd, len, flags int32) (int32, []byte, error)

RecvWithErrno calls recv on the DUT.

func (*DUT) Send

func (dut *DUT) Send(t *testing.T, sockfd int32, buf []byte, flags int32) int32

Send calls send on the DUT and causes a fatal test failure if it doesn't succeed. If more control over the timeout or error handling is needed, use SendWithErrno.

func (*DUT) SendTo

func (dut *DUT) SendTo(t *testing.T, sockfd int32, buf []byte, flags int32, destAddr unix.Sockaddr) int32

SendTo calls sendto on the DUT and causes a fatal test failure if it doesn't succeed. If more control over the timeout or error handling is needed, use SendToWithErrno.

func (*DUT) SendToWithErrno

func (dut *DUT) SendToWithErrno(ctx context.Context, t *testing.T, sockfd int32, buf []byte, flags int32, destAddr unix.Sockaddr) (int32, error)

SendToWithErrno calls sendto on the DUT.

func (*DUT) SendWithErrno

func (dut *DUT) SendWithErrno(ctx context.Context, t *testing.T, sockfd int32, buf []byte, flags int32) (int32, error)

SendWithErrno calls send on the DUT.

func (*DUT) SetNonBlocking

func (dut *DUT) SetNonBlocking(t *testing.T, fd int32, nonblocking bool)

SetNonBlocking will set O_NONBLOCK flag for fd if nonblocking is true, otherwise it will clear the flag.

func (*DUT) SetSockLingerOption

func (dut *DUT) SetSockLingerOption(t *testing.T, sockfd int32, timeout time.Duration, enable bool)

SetSockLingerOption sets SO_LINGER socket option on the DUT.

func (*DUT) SetSockOpt

func (dut *DUT) SetSockOpt(t *testing.T, sockfd, level, optname int32, optval []byte)

SetSockOpt calls setsockopt on the DUT and causes a fatal test failure if it doesn't succeed. If more control over the timeout or error handling is needed, use SetSockOptWithErrno. Because endianess and the width of values might differ between the testbench and DUT architectures, prefer to use a more specific SetSockOptXxx function.

func (*DUT) SetSockOptInt

func (dut *DUT) SetSockOptInt(t *testing.T, sockfd, level, optname, optval int32)

SetSockOptInt calls setsockopt on the DUT and causes a fatal test failure if it doesn't succeed. If more control over the int optval or error handling is needed, use SetSockOptIntWithErrno.

func (*DUT) SetSockOptIntWithErrno

func (dut *DUT) SetSockOptIntWithErrno(ctx context.Context, t *testing.T, sockfd, level, optname, optval int32) (int32, error)

SetSockOptIntWithErrno calls setsockopt with an integer optval.

func (*DUT) SetSockOptTimeval

func (dut *DUT) SetSockOptTimeval(t *testing.T, sockfd, level, optname int32, tv *unix.Timeval)

SetSockOptTimeval calls setsockopt on the DUT and causes a fatal test failure if it doesn't succeed. If more control over the timeout or error handling is needed, use SetSockOptTimevalWithErrno.

func (*DUT) SetSockOptTimevalWithErrno

func (dut *DUT) SetSockOptTimevalWithErrno(ctx context.Context, t *testing.T, sockfd, level, optname int32, tv *unix.Timeval) (int32, error)

SetSockOptTimevalWithErrno calls setsockopt with the timeval converted to bytes.

func (*DUT) SetSockOptWithErrno

func (dut *DUT) SetSockOptWithErrno(ctx context.Context, t *testing.T, sockfd, level, optname int32, optval []byte) (int32, error)

SetSockOptWithErrno calls setsockopt on the DUT. Because endianess and the width of values might differ between the testbench and DUT architectures, prefer to use a more specific SetSockOptXxxWithErrno function.

func (*DUT) Shutdown

func (dut *DUT) Shutdown(t *testing.T, fd, how int32)

Shutdown calls shutdown on the DUT and causes a fatal test failure if it doesn't succeed. If more control over the timeout or error handling is needed, use ShutdownWithErrno.

func (*DUT) ShutdownWithErrno

func (dut *DUT) ShutdownWithErrno(ctx context.Context, t *testing.T, fd, how int32) (int32, error)

ShutdownWithErrno calls shutdown on the DUT.

func (*DUT) Socket

func (dut *DUT) Socket(t *testing.T, domain, typ, proto int32) int32

Socket calls socket on the DUT and returns the file descriptor. If socket fails on the DUT, the test ends.

func (*DUT) SocketWithErrno

func (dut *DUT) SocketWithErrno(t *testing.T, domain, typ, proto int32) (int32, error)

SocketWithErrno calls socket on the DUT and returns the fd and errno.

func (*DUT) TearDownConnection

func (dut *DUT) TearDownConnection()

TearDownConnection closes the underlying connection.

type DUTInfo

type DUTInfo struct {
	Uname *DUTUname
	Net   *DUTTestNet
}

DUTInfo has both network and uname information about the DUT.

func (*DUTInfo) ConnectToDUT

func (info *DUTInfo) ConnectToDUT(t *testing.T) DUT

ConnectToDUT connects to DUT through gRPC.

type DUTTestNet

type DUTTestNet struct {
	// LocalMAC is the local MAC address on the test network.
	LocalMAC net.HardwareAddr
	// RemoteMAC is the DUT's MAC address on the test network.
	RemoteMAC net.HardwareAddr
	// LocalIPv4 is the local IPv4 address on the test network.
	LocalIPv4 net.IP
	// RemoteIPv4 is the DUT's IPv4 address on the test network.
	RemoteIPv4 net.IP
	// IPv4PrefixLength is the network prefix length of the IPv4 test network.
	IPv4PrefixLength int
	// LocalIPv6 is the local IPv6 address on the test network.
	LocalIPv6 net.IP
	// RemoteIPv6 is the DUT's IPv6 address on the test network.
	RemoteIPv6 net.IP
	// LocalDevID is the ID of the local interface on the test network.
	LocalDevID uint32
	// RemoteDevID is the ID of the remote interface on the test network.
	RemoteDevID uint32
	// LocalDevName is the device that testbench uses to inject traffic.
	LocalDevName string
	// RemoteDevName is the device name on the DUT, individual tests can
	// use the name to construct tests.
	RemoteDevName string

	// POSIXServerIP is the POSIX server's IP address on the control network.
	POSIXServerIP net.IP
	// POSIXServerPort is the UDP port the POSIX server is bound to on the
	// control network.
	POSIXServerPort uint16
}

DUTTestNet describes the test network setup on dut and how the testbench should connect with an existing DUT.

func (*DUTTestNet) NewIPv4Conn

func (n *DUTTestNet) NewIPv4Conn(t *testing.T, outgoingIPv4, incomingIPv4 IPv4) IPv4Conn

NewIPv4Conn creates a new IPv4Conn connection with reasonable defaults.

func (*DUTTestNet) NewIPv6Conn

func (n *DUTTestNet) NewIPv6Conn(t *testing.T, outgoingIPv6, incomingIPv6 IPv6) IPv6Conn

NewIPv6Conn creates a new IPv6Conn connection with reasonable defaults.

func (*DUTTestNet) NewInjector

func (n *DUTTestNet) NewInjector(t *testing.T) (Injector, error)

NewInjector creates a new injector on *device.

func (*DUTTestNet) NewSniffer

func (n *DUTTestNet) NewSniffer(t *testing.T) (Sniffer, error)

NewSniffer creates a Sniffer connected to *device.

func (*DUTTestNet) NewTCPIPv4

func (n *DUTTestNet) NewTCPIPv4(t *testing.T, outgoingTCP, incomingTCP TCP) TCPIPv4

NewTCPIPv4 creates a new TCPIPv4 connection with reasonable defaults.

func (*DUTTestNet) NewTCPIPv6

func (n *DUTTestNet) NewTCPIPv6(t *testing.T, outgoingTCP, incomingTCP TCP) TCPIPv6

NewTCPIPv6 creates a new TCPIPv6 connection with reasonable defaults.

func (*DUTTestNet) NewUDPIPv4

func (n *DUTTestNet) NewUDPIPv4(t *testing.T, outgoingUDP, incomingUDP UDP) UDPIPv4

NewUDPIPv4 creates a new UDPIPv4 connection with reasonable defaults.

func (*DUTTestNet) NewUDPIPv6

func (n *DUTTestNet) NewUDPIPv6(t *testing.T, outgoingUDP, incomingUDP UDP) UDPIPv6

NewUDPIPv6 creates a new UDPIPv6 connection with reasonable defaults.

func (*DUTTestNet) SubnetBroadcast

func (n *DUTTestNet) SubnetBroadcast() net.IP

SubnetBroadcast returns the test network's subnet broadcast address.

type DUTUname

type DUTUname struct {
	Machine         string
	KernelName      string
	KernelRelease   string
	KernelVersion   string
	OperatingSystem string
}

DUTUname contains information about the DUT from uname.

func (*DUTUname) IsFuchsia

func (n *DUTUname) IsFuchsia() bool

IsFuchsia returns true if the DUT is running Fuchsia.

func (*DUTUname) IsGvisor

func (*DUTUname) IsGvisor() bool

IsGvisor returns true if the DUT is running gVisor.

func (*DUTUname) IsLinux

func (n *DUTUname) IsLinux() bool

IsLinux returns true if the DUT is running Linux.

type Ether

type Ether struct {
	LayerBase
	SrcAddr *tcpip.LinkAddress
	DstAddr *tcpip.LinkAddress
	Type    *tcpip.NetworkProtocolNumber
}

Ether can construct and match an ethernet encapsulation.

func (*Ether) String

func (l *Ether) String() string

func (*Ether) ToBytes

func (l *Ether) ToBytes() ([]byte, error)

ToBytes implements Layer.ToBytes.

type ICMPv4

type ICMPv4 struct {
	LayerBase
	Type     *header.ICMPv4Type
	Code     *header.ICMPv4Code
	Checksum *uint16
	Ident    *uint16 // Only in Echo Request/Reply.
	Sequence *uint16 // Only in Echo Request/Reply.
	Pointer  *uint8  // Only in Parameter Problem.
	Payload  []byte
}

ICMPv4 can construct and match an ICMPv4 encapsulation.

func (*ICMPv4) String

func (l *ICMPv4) String() string

func (*ICMPv4) ToBytes

func (l *ICMPv4) ToBytes() ([]byte, error)

ToBytes implements Layer.ToBytes.

type ICMPv6

type ICMPv6 struct {
	LayerBase
	Type     *header.ICMPv6Type
	Code     *header.ICMPv6Code
	Checksum *uint16
	Ident    *uint16 // Only in Echo Request/Reply.
	Pointer  *uint32 // Only in Parameter Problem.
	Payload  []byte
}

ICMPv6 can construct and match an ICMPv6 encapsulation.

func (*ICMPv6) String

func (l *ICMPv6) String() string

func (*ICMPv6) ToBytes

func (l *ICMPv6) ToBytes() ([]byte, error)

ToBytes implements Layer.ToBytes.

type IPv4

type IPv4 struct {
	LayerBase
	IHL            *uint8
	TOS            *uint8
	TotalLength    *uint16
	ID             *uint16
	Flags          *uint8
	FragmentOffset *uint16
	TTL            *uint8
	Protocol       *uint8
	Checksum       *uint16
	SrcAddr        *tcpip.Address
	DstAddr        *tcpip.Address
	Options        *header.IPv4Options
}

IPv4 can construct and match an IPv4 encapsulation.

func (*IPv4) String

func (l *IPv4) String() string

func (*IPv4) ToBytes

func (l *IPv4) ToBytes() ([]byte, error)

ToBytes implements Layer.ToBytes.

type IPv4Conn

type IPv4Conn struct {
	Connection
}

IPv4Conn maintains the state for all the layers in a IPv4 connection.

func (*IPv4Conn) Send

func (c *IPv4Conn) Send(t *testing.T, ipv4 IPv4, additionalLayers ...Layer)

Send sends a frame with ipv4 overriding the IPv4 layer defaults and additionalLayers added after it.

type IPv6

type IPv6 struct {
	LayerBase
	TrafficClass  *uint8
	FlowLabel     *uint32
	PayloadLength *uint16
	NextHeader    *uint8
	HopLimit      *uint8
	SrcAddr       *tcpip.Address
	DstAddr       *tcpip.Address
}

IPv6 can construct and match an IPv6 encapsulation.

func (*IPv6) String

func (l *IPv6) String() string

func (*IPv6) ToBytes

func (l *IPv6) ToBytes() ([]byte, error)

ToBytes implements Layer.ToBytes.

type IPv6Conn

type IPv6Conn struct {
	Connection
}

IPv6Conn maintains the state for all the layers in a IPv6 connection.

func (*IPv6Conn) Send

func (conn *IPv6Conn) Send(t *testing.T, ipv6 IPv6, additionalLayers ...Layer)

Send sends a frame with ipv6 overriding the IPv6 layer defaults and additionalLayers added after it.

type IPv6DestinationOptionsExtHdr

type IPv6DestinationOptionsExtHdr struct {
	LayerBase
	NextHeader *header.IPv6ExtensionHeaderIdentifier
	Options    []byte
}

IPv6DestinationOptionsExtHdr can construct and match an IPv6DestinationOptions Extension Header.

func (*IPv6DestinationOptionsExtHdr) String

func (*IPv6DestinationOptionsExtHdr) ToBytes

func (l *IPv6DestinationOptionsExtHdr) ToBytes() ([]byte, error)

ToBytes implements Layer.ToBytes.

type IPv6FragmentExtHdr

type IPv6FragmentExtHdr struct {
	LayerBase
	NextHeader     *header.IPv6ExtensionHeaderIdentifier
	FragmentOffset *uint16
	MoreFragments  *bool
	Identification *uint32
}

IPv6FragmentExtHdr can construct and match an IPv6 Fragment Extension Header.

func (*IPv6FragmentExtHdr) String

func (l *IPv6FragmentExtHdr) String() string

func (*IPv6FragmentExtHdr) ToBytes

func (l *IPv6FragmentExtHdr) ToBytes() ([]byte, error)

ToBytes implements Layer.ToBytes.

type IPv6HopByHopOptionsExtHdr

type IPv6HopByHopOptionsExtHdr struct {
	LayerBase
	NextHeader *header.IPv6ExtensionHeaderIdentifier
	Options    []byte
}

IPv6HopByHopOptionsExtHdr can construct and match an IPv6HopByHopOptions Extension Header.

func (*IPv6HopByHopOptionsExtHdr) String

func (l *IPv6HopByHopOptionsExtHdr) String() string

func (*IPv6HopByHopOptionsExtHdr) ToBytes

func (l *IPv6HopByHopOptionsExtHdr) ToBytes() ([]byte, error)

ToBytes implements Layer.ToBytes.

type Injector

type Injector struct {
	// contains filtered or unexported fields
}

Injector can inject raw frames.

func (*Injector) Send

func (i *Injector) Send(t *testing.T, b []byte)

Send a raw frame.

type Layer

type Layer interface {
	fmt.Stringer

	// ToBytes converts the Layer into bytes. In places where the Layer's field
	// isn't nil, the value that is pointed to is used. When the field is nil, a
	// reasonable default for the Layer is used. For example, "64" for IPv4 TTL
	// and a calculated checksum for TCP or IP. Some layers require information
	// from the previous or next layers in order to compute a default, such as
	// TCP's checksum or Ethernet's type, so each Layer has a doubly-linked list
	// to the layer's neighbors.
	ToBytes() ([]byte, error)

	// prev gets a pointer to the Layer encapsulating this one.
	Prev() Layer
	// contains filtered or unexported methods
}

Layer is the interface that all encapsulations must implement.

A Layer is an encapsulation in a packet, such as TCP, IPv4, IPv6, etc. A Layer contains all the fields of the encapsulation. Each field is a pointer and may be nil.

type LayerBase

type LayerBase struct {
	// contains filtered or unexported fields
}

LayerBase is the common elements of all layers.

func (*LayerBase) Prev

func (lb *LayerBase) Prev() Layer

Prev returns the previous layer.

type Layers

type Layers []Layer

Layers is an array of Layer and supports similar functions to Layer.

func (*Layers) ToBytes

func (ls *Layers) ToBytes() ([]byte, error)

ToBytes converts the Layers into bytes. It creates a linked list of the Layer structs and then concatentates the output of ToBytes on each Layer.

type POSIXClient

type POSIXClient pb.PosixClient

POSIXClient is a gRPC client for the Posix service.

func NewPOSIXClient

func NewPOSIXClient(c grpc.ClientConnInterface) POSIXClient

NewPOSIXClient makes a new gRPC client for the POSIX service.

type Payload

type Payload struct {
	LayerBase
	Bytes []byte
}

Payload has bytes beyond OSI layer 4.

func (*Payload) Length

func (l *Payload) Length() int

Length returns payload byte length.

func (*Payload) String

func (l *Payload) String() string

func (*Payload) ToBytes

func (l *Payload) ToBytes() ([]byte, error)

ToBytes implements Layer.ToBytes.

type Sniffer

type Sniffer struct {
	// contains filtered or unexported fields
}

Sniffer can sniff raw packets on the wire.

func (*Sniffer) Drain

func (s *Sniffer) Drain(t *testing.T)

Drain drains the Sniffer's socket receive buffer by receiving until there's nothing else to receive.

func (*Sniffer) Recv

func (s *Sniffer) Recv(t *testing.T, timeout time.Duration) []byte

Recv tries to read one frame until the timeout is up. If the timeout given is 0, then no read attempt will be made.

type TCP

type TCP struct {
	LayerBase
	SrcPort       *uint16
	DstPort       *uint16
	SeqNum        *uint32
	AckNum        *uint32
	DataOffset    *uint8
	Flags         *header.TCPFlags
	WindowSize    *uint16
	Checksum      *uint16
	UrgentPointer *uint16
	Options       []byte
}

TCP can construct and match a TCP encapsulation.

func GenerateOTWSeqSegment

func GenerateOTWSeqSegment(t *testing.T, conn *TCPIPv4, seqNumOffset seqnum.Size, windowSize seqnum.Size) TCP

GenerateOTWSeqSegment generates a segment with seqnum = RCV.NXT + RCV.WND + seqNumOffset, the generated segment is only acceptable when seqNumOffset is 0, otherwise an ACK is expected from the receiver.

func GenerateUnaccACKSegment

func GenerateUnaccACKSegment(t *testing.T, conn *TCPIPv4, seqNumOffset seqnum.Size, windowSize seqnum.Size) TCP

GenerateUnaccACKSegment generates a segment with acknum = SND.NXT + seqNumOffset, the generated segment is only acceptable when seqNumOffset is 0, otherwise an ACK is expected from the receiver.

func (*TCP) String

func (l *TCP) String() string

func (*TCP) ToBytes

func (l *TCP) ToBytes() ([]byte, error)

ToBytes implements Layer.ToBytes.

type TCPIPv4

type TCPIPv4 struct {
	Connection
}

TCPIPv4 maintains the state for all the layers in a TCP/IPv4 connection.

func (*TCPIPv4) Connect

func (conn *TCPIPv4) Connect(t *testing.T)

Connect performs a TCP 3-way handshake. The input Connection should have a final TCP Layer.

func (*TCPIPv4) ConnectWithOptions

func (conn *TCPIPv4) ConnectWithOptions(t *testing.T, options []byte)

ConnectWithOptions performs a TCP 3-way handshake with given TCP options. The input Connection should have a final TCP Layer.

func (*TCPIPv4) Expect

func (conn *TCPIPv4) Expect(t *testing.T, tcp TCP, timeout time.Duration) (*TCP, error)

Expect expects a frame with the TCP layer matching the provided TCP within the timeout specified. If it doesn't arrive in time, an error is returned.

func (*TCPIPv4) ExpectData

func (conn *TCPIPv4) ExpectData(t *testing.T, tcp *TCP, payload *Payload, timeout time.Duration) (Layers, error)

ExpectData is a convenient method that expects a Layer and the Layer after it. If it doesn't arrive in time, it returns nil.

func (*TCPIPv4) ExpectNextData

func (conn *TCPIPv4) ExpectNextData(t *testing.T, tcp *TCP, payload *Payload, timeout time.Duration) (Layers, error)

ExpectNextData attempts to receive the next incoming segment for the connection and expects that to match the given layers.

It differs from ExpectData() in that here we are only interested in the next received segment, while ExpectData() can receive multiple segments for the connection until there is a match with given layers or a timeout.

func (*TCPIPv4) LocalAddr

func (conn *TCPIPv4) LocalAddr(t *testing.T) *unix.SockaddrInet4

LocalAddr gets the local socket address of this connection.

func (*TCPIPv4) LocalSeqNum

func (conn *TCPIPv4) LocalSeqNum(t *testing.T) *seqnum.Value

LocalSeqNum returns the next sequence number to send from the testbench.

func (*TCPIPv4) RemoteSeqNum

func (conn *TCPIPv4) RemoteSeqNum(t *testing.T) *seqnum.Value

RemoteSeqNum returns the next expected sequence number from the DUT.

func (*TCPIPv4) Send

func (conn *TCPIPv4) Send(t *testing.T, tcp TCP, additionalLayers ...Layer)

Send a packet with reasonable defaults. Potentially override the TCP layer in the connection with the provided layer and add additionLayers.

func (*TCPIPv4) SynAck

func (conn *TCPIPv4) SynAck(t *testing.T) *TCP

SynAck returns the SynAck that was part of the handshake.

type TCPIPv6

type TCPIPv6 struct {
	Connection
}

TCPIPv6 maintains the state for all the layers in a TCP/IPv6 connection.

func (*TCPIPv6) ExpectData

func (conn *TCPIPv6) ExpectData(t *testing.T, tcp *TCP, payload *Payload, timeout time.Duration) (Layers, error)

ExpectData is a convenient method that expects a Layer and the Layer after it. If it doesn't arrive in time, it returns nil.

func (*TCPIPv6) SrcPort

func (conn *TCPIPv6) SrcPort() uint16

SrcPort returns the source port from the given Connection.

type UDP

type UDP struct {
	LayerBase
	SrcPort  *uint16
	DstPort  *uint16
	Length   *uint16
	Checksum *uint16
}

UDP can construct and match a UDP encapsulation.

func (*UDP) String

func (l *UDP) String() string

func (*UDP) ToBytes

func (l *UDP) ToBytes() ([]byte, error)

ToBytes implements Layer.ToBytes.

type UDPIPv4

type UDPIPv4 struct {
	Connection
}

UDPIPv4 maintains the state for all the layers in a UDP/IPv4 connection.

func (*UDPIPv4) Expect

func (conn *UDPIPv4) Expect(t *testing.T, udp UDP, timeout time.Duration) (*UDP, error)

Expect expects a frame with the UDP layer matching the provided UDP within the timeout specified. If it doesn't arrive in time, an error is returned.

func (*UDPIPv4) ExpectData

func (conn *UDPIPv4) ExpectData(t *testing.T, udp UDP, payload Payload, timeout time.Duration) (Layers, error)

ExpectData is a convenient method that expects a Layer and the Layer after it. If it doesn't arrive in time, it returns nil.

func (*UDPIPv4) LocalAddr

func (conn *UDPIPv4) LocalAddr(t *testing.T) *unix.SockaddrInet4

LocalAddr gets the local socket address of this connection.

func (*UDPIPv4) Send

func (conn *UDPIPv4) Send(t *testing.T, udp UDP, additionalLayers ...Layer)

Send sends a packet with reasonable defaults, potentially overriding the UDP layer and adding additionLayers.

func (*UDPIPv4) SendFrame

func (conn *UDPIPv4) SendFrame(t *testing.T, overrideLayers Layers, additionalLayers ...Layer)

SendFrame sends a frame on the wire and updates the state of all layers.

func (*UDPIPv4) SendIP

func (conn *UDPIPv4) SendIP(t *testing.T, ip IPv4, udp UDP, additionalLayers ...Layer)

SendIP sends a packet with reasonable defaults, potentially overriding the UDP and IPv4 headers and adding additionLayers.

func (*UDPIPv4) SrcPort

func (conn *UDPIPv4) SrcPort(t *testing.T) uint16

SrcPort returns the source port of this connection.

type UDPIPv6

type UDPIPv6 struct {
	Connection
}

UDPIPv6 maintains the state for all the layers in a UDP/IPv6 connection.

func (*UDPIPv6) Expect

func (conn *UDPIPv6) Expect(t *testing.T, udp UDP, timeout time.Duration) (*UDP, error)

Expect expects a frame with the UDP layer matching the provided UDP within the timeout specified. If it doesn't arrive in time, an error is returned.

func (*UDPIPv6) ExpectData

func (conn *UDPIPv6) ExpectData(t *testing.T, udp UDP, payload Payload, timeout time.Duration) (Layers, error)

ExpectData is a convenient method that expects a Layer and the Layer after it. If it doesn't arrive in time, it returns nil.

func (*UDPIPv6) LocalAddr

func (conn *UDPIPv6) LocalAddr(t *testing.T, zoneID uint32) *unix.SockaddrInet6

LocalAddr gets the local socket address of this connection.

func (*UDPIPv6) Send

func (conn *UDPIPv6) Send(t *testing.T, udp UDP, additionalLayers ...Layer)

Send sends a packet with reasonable defaults, potentially overriding the UDP layer and adding additionLayers.

func (*UDPIPv6) SendFrame

func (conn *UDPIPv6) SendFrame(t *testing.T, overrideLayers Layers, additionalLayers ...Layer)

SendFrame sends a frame on the wire and updates the state of all layers.

func (*UDPIPv6) SendIPv6

func (conn *UDPIPv6) SendIPv6(t *testing.T, ip IPv6, udp UDP, additionalLayers ...Layer)

SendIPv6 sends a packet with reasonable defaults, potentially overriding the UDP and IPv6 headers and adding additionLayers.

func (*UDPIPv6) SrcPort

func (conn *UDPIPv6) SrcPort(t *testing.T) uint16

SrcPort returns the source port of this connection.

Jump to

Keyboard shortcuts

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