Back to godoc.org

Package testbench

v0.0.0 (4fa1c30)
Latest Go to latest
Published: today | Licenses: Apache-2.0 , MIT | Module: gvisor.dev/gvisor

Overview

Package testbench has utilities to send and receive packets and also command the DUT to run POSIX functions.

Index

Package Files

Variables

var (
	// Native indicates that the test is being run natively.
	Native = false
	// Device is the local device on the test network.
	Device = ""

	// LocalIPv4 is the local IPv4 address on the test network.
	LocalIPv4 = ""
	// RemoteIPv4 is the DUT's IPv4 address on the test network.
	RemoteIPv4 = ""
	// IPv4PrefixLength is the network prefix length of the IPv4 test network.
	IPv4PrefixLength = 0

	// LocalIPv6 is the local IPv6 address on the test network.
	LocalIPv6 = ""
	// RemoteIPv6 is the DUT's IPv6 address on the test network.
	RemoteIPv6 = ""

	// LocalInterfaceID is the ID of the local interface on the test network.
	LocalInterfaceID uint32
	// RemoteInterfaceID is the ID of the remote interface on the test network.
	//
	// Not using uint32 because package flag does not support uint32.
	RemoteInterfaceID uint64

	// LocalMAC is the local MAC address on the test network.
	LocalMAC = ""
	// RemoteMAC is the DUT's MAC address on the test network.
	RemoteMAC = ""

	// POSIXServerIP is the POSIX server's IP address on the control network.
	POSIXServerIP = ""
	// POSIXServerPort is the UDP port the POSIX server is bound to on the
	// control network.
	POSIXServerPort = 40000

	// RPCKeepalive is the gRPC keepalive.
	RPCKeepalive = 10 * time.Second
	// RPCTimeout is the gRPC timeout.
	RPCTimeout = 100 * time.Millisecond
)

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 Byte

func Byte(v byte) *byte

Byte is a helper routine that allocates a new byte 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 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 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

func IPv6ExtHdrIdent(id header.IPv6ExtensionHeaderIdentifier) *header.IPv6ExtensionHeaderIdentifier

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

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 RegisterFlags

func RegisterFlags(fs *flag.FlagSet)

RegisterFlags defines flags and associates them with the package-level exported variables above. It should be called by tests in their init functions.

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 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.

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 overriden 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 overriden 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) 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 {
	// 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) Fcntl

func (dut *DUT) Fcntl(t *testing.T, fd, cmd, arg int32) int32

Fcntl calls fcntl 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 FcntlWithErrno.

func (*DUT) FcntlWithErrno

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

FcntlWithErrno calls fcntl on the DUT.

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) 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) 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) 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) 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) TearDown

func (dut *DUT) TearDown()

TearDown closes the underlying connection.

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     *uint8
	Checksum *uint16
}

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     *byte
	Checksum *uint16
	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
}

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 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 Connection

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

func NewIPv6Conn

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

NewIPv6Conn creates a new IPv6Conn connection with reasonable defaults.

func (*IPv6Conn) Close

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

Close to clean up any resources held.

func (*IPv6Conn) ExpectFrame

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

ExpectFrame expects a frame that matches the provided Layers within the timeout specified. If it doesn't arrive in time, an error is returned.

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 (l *IPv6DestinationOptionsExtHdr) String() 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 NewInjector

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

NewInjector creates a new injector on *device.

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 NewSniffer

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

NewSniffer creates a Sniffer connected to *device.

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.

type TCP

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

TCP can construct and match a TCP encapsulation.

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 Connection

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

func NewTCPIPv4

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

NewTCPIPv4 creates a new TCPIPv4 connection with reasonable defaults.

func (*TCPIPv4) Close

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

Close frees associated resources held by the TCPIPv4 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) Drain

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

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

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 doens'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 Connection

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

func NewTCPIPv6

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

NewTCPIPv6 creates a new TCPIPv6 connection with reasonable defaults.

func (*TCPIPv6) Close

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

Close frees associated resources held by the TCPIPv6 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 doens't arrive in time, it returns nil.

func (*TCPIPv6) SrcPort

func (conn *TCPIPv6) SrcPort() uint16

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 Connection

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

func NewUDPIPv4

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

NewUDPIPv4 creates a new UDPIPv4 connection with reasonable defaults.

func (*UDPIPv4) Close

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

Close frees associated resources held by the UDPIPv4 connection.

func (*UDPIPv4) Drain

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

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

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 doens'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) 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.

type UDPIPv6

type UDPIPv6 Connection

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

func NewUDPIPv6

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

NewUDPIPv6 creates a new UDPIPv6 connection with reasonable defaults.

func (*UDPIPv6) Close

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

Close frees associated resources held by the UDPIPv6 connection.

func (*UDPIPv6) Drain

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

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

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 doens't arrive in time, it returns nil.

func (*UDPIPv6) LocalAddr

func (conn *UDPIPv6) LocalAddr(t *testing.T) *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) 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.

Documentation was rendered with GOOS=linux and GOARCH=amd64.

Jump to identifier

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to identifier