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 ¶
- Variables
- func Address(v tcpip.Address) *net.IP
- func Bool(v bool) *bool
- func GenerateRandomPayload(t *testing.T, n int) []byte
- func ICMPv4Code(t header.ICMPv4Code) *header.ICMPv4Code
- func ICMPv4Type(t header.ICMPv4Type) *header.ICMPv4Type
- func ICMPv6Code(v header.ICMPv6Code) *header.ICMPv6Code
- func ICMPv6Type(v header.ICMPv6Type) *header.ICMPv6Type
- func IPv6ExtHdrIdent(id header.IPv6ExtensionHeaderIdentifier) *header.IPv6ExtensionHeaderIdentifier
- func Initialize(fs *flag.FlagSet)
- func LinkAddress(v tcpip.LinkAddress) *tcpip.LinkAddress
- func NetworkProtocolNumber(v tcpip.NetworkProtocolNumber) *tcpip.NetworkProtocolNumber
- func SeqNumValue(v seqnum.Value) *seqnum.Value
- func TCPFlags(v header.TCPFlags) *header.TCPFlags
- func Uint16(v uint16) *uint16
- func Uint32(v uint32) *uint32
- func Uint8(v uint8) *uint8
- type Connection
- func (conn *Connection) Close(t *testing.T)
- func (conn *Connection) CreateFrame(t *testing.T, overrideLayers Layers, additionalLayers ...Layer) Layers
- func (conn *Connection) Drain(t *testing.T)
- func (conn *Connection) Expect(t *testing.T, layer Layer, timeout time.Duration) (Layer, error)
- func (conn *Connection) ExpectFrame(t *testing.T, layers Layers, timeout time.Duration) (Layers, error)
- func (conn *Connection) ListenForFrame(t *testing.T, layers Layers, timeout time.Duration) ([]Layers, bool)
- func (conn *Connection) SendFrame(t *testing.T, frame Layers)
- func (conn *Connection) SendFrameStateless(t *testing.T, frame Layers)
- type DUT
- func (dut *DUT) Accept(t *testing.T, sockfd int32) (int32, unix.Sockaddr)
- func (dut *DUT) AcceptWithErrno(ctx context.Context, t *testing.T, sockfd int32) (int32, unix.Sockaddr, error)
- func (dut *DUT) Bind(t *testing.T, fd int32, sa unix.Sockaddr)
- func (dut *DUT) BindWithErrno(ctx context.Context, t *testing.T, fd int32, sa unix.Sockaddr) (int32, error)
- func (dut *DUT) Close(t *testing.T, fd int32)
- func (dut *DUT) CloseWithErrno(ctx context.Context, t *testing.T, fd int32) (int32, error)
- func (dut *DUT) Connect(t *testing.T, fd int32, sa unix.Sockaddr)
- func (dut *DUT) ConnectWithErrno(ctx context.Context, t *testing.T, fd int32, sa unix.Sockaddr) (int32, error)
- func (dut *DUT) CreateBoundSocket(t *testing.T, typ, proto int32, addr net.IP) (int32, uint16)
- func (dut *DUT) CreateListener(t *testing.T, typ, proto, backlog int32) (int32, uint16)
- func (dut *DUT) GetSockName(t *testing.T, sockfd int32) unix.Sockaddr
- func (dut *DUT) GetSockNameWithErrno(ctx context.Context, t *testing.T, sockfd int32) (int32, unix.Sockaddr, error)
- func (dut *DUT) GetSockOpt(t *testing.T, sockfd, level, optname, optlen int32) []byte
- func (dut *DUT) GetSockOptInt(t *testing.T, sockfd, level, optname int32) int32
- func (dut *DUT) GetSockOptIntWithErrno(ctx context.Context, t *testing.T, sockfd, level, optname int32) (int32, int32, error)
- func (dut *DUT) GetSockOptTCPInfo(t *testing.T, sockfd int32) linux.TCPInfo
- func (dut *DUT) GetSockOptTCPInfoWithErrno(ctx context.Context, t *testing.T, sockfd int32) (int32, linux.TCPInfo, error)
- func (dut *DUT) GetSockOptTimeval(t *testing.T, sockfd, level, optname int32) unix.Timeval
- func (dut *DUT) GetSockOptTimevalWithErrno(ctx context.Context, t *testing.T, sockfd, level, optname int32) (int32, unix.Timeval, error)
- func (dut *DUT) GetSockOptWithErrno(ctx context.Context, t *testing.T, sockfd, level, optname, optlen int32) (int32, []byte, error)
- func (dut *DUT) Listen(t *testing.T, sockfd, backlog int32)
- func (dut *DUT) ListenWithErrno(ctx context.Context, t *testing.T, sockfd, backlog int32) (int32, error)
- func (dut *DUT) Poll(t *testing.T, pfds []unix.PollFd, timeout time.Duration) []unix.PollFd
- func (dut *DUT) PollOne(t *testing.T, fd int32, events int16, timeout time.Duration)
- func (dut *DUT) PollWithErrno(ctx context.Context, t *testing.T, pfds []unix.PollFd, timeout time.Duration) (int32, []unix.PollFd, error)
- func (dut *DUT) Recv(t *testing.T, sockfd, len, flags int32) []byte
- func (dut *DUT) RecvWithErrno(ctx context.Context, t *testing.T, sockfd, len, flags int32) (int32, []byte, error)
- func (dut *DUT) Send(t *testing.T, sockfd int32, buf []byte, flags int32) int32
- func (dut *DUT) SendTo(t *testing.T, sockfd int32, buf []byte, flags int32, destAddr unix.Sockaddr) int32
- func (dut *DUT) SendToWithErrno(ctx context.Context, t *testing.T, sockfd int32, buf []byte, flags int32, ...) (int32, error)
- func (dut *DUT) SendWithErrno(ctx context.Context, t *testing.T, sockfd int32, buf []byte, flags int32) (int32, error)
- func (dut *DUT) SetNonBlocking(t *testing.T, fd int32, nonblocking bool)
- func (dut *DUT) SetSockLingerOption(t *testing.T, sockfd int32, timeout time.Duration, enable bool)
- func (dut *DUT) SetSockOpt(t *testing.T, sockfd, level, optname int32, optval []byte)
- func (dut *DUT) SetSockOptInt(t *testing.T, sockfd, level, optname, optval int32)
- func (dut *DUT) SetSockOptIntWithErrno(ctx context.Context, t *testing.T, sockfd, level, optname, optval int32) (int32, error)
- func (dut *DUT) SetSockOptTimeval(t *testing.T, sockfd, level, optname int32, tv *unix.Timeval)
- func (dut *DUT) SetSockOptTimevalWithErrno(ctx context.Context, t *testing.T, sockfd, level, optname int32, ...) (int32, error)
- func (dut *DUT) SetSockOptWithErrno(ctx context.Context, t *testing.T, sockfd, level, optname int32, optval []byte) (int32, error)
- func (dut *DUT) Shutdown(t *testing.T, fd, how int32)
- func (dut *DUT) ShutdownWithErrno(ctx context.Context, t *testing.T, fd, how int32) (int32, error)
- func (dut *DUT) Socket(t *testing.T, domain, typ, proto int32) int32
- func (dut *DUT) SocketWithErrno(t *testing.T, domain, typ, proto int32) (int32, error)
- func (dut *DUT) TearDownConnection()
- type DUTInfo
- type DUTTestNet
- func (n *DUTTestNet) NewIPv4Conn(t *testing.T, outgoingIPv4, incomingIPv4 IPv4) IPv4Conn
- func (n *DUTTestNet) NewIPv6Conn(t *testing.T, outgoingIPv6, incomingIPv6 IPv6) IPv6Conn
- func (n *DUTTestNet) NewInjector(t *testing.T) (Injector, error)
- func (n *DUTTestNet) NewSniffer(t *testing.T) (Sniffer, error)
- func (n *DUTTestNet) NewTCPIPv4(t *testing.T, outgoingTCP, incomingTCP TCP) TCPIPv4
- func (n *DUTTestNet) NewTCPIPv6(t *testing.T, outgoingTCP, incomingTCP TCP) TCPIPv6
- func (n *DUTTestNet) NewUDPIPv4(t *testing.T, outgoingUDP, incomingUDP UDP) UDPIPv4
- func (n *DUTTestNet) NewUDPIPv6(t *testing.T, outgoingUDP, incomingUDP UDP) UDPIPv6
- func (n *DUTTestNet) SubnetBroadcast() net.IP
- type DUTUname
- type Ether
- type ICMPv4
- type ICMPv6
- type IPv4
- type IPv4Conn
- type IPv6
- type IPv6Conn
- type IPv6DestinationOptionsExtHdr
- type IPv6FragmentExtHdr
- type IPv6HopByHopOptionsExtHdr
- type Injector
- type Layer
- type LayerBase
- type Layers
- type POSIXClient
- type Payload
- type Sniffer
- type TCP
- type TCPIPv4
- func (conn *TCPIPv4) Connect(t *testing.T)
- func (conn *TCPIPv4) ConnectWithOptions(t *testing.T, options []byte)
- func (conn *TCPIPv4) Expect(t *testing.T, tcp TCP, timeout time.Duration) (*TCP, error)
- func (conn *TCPIPv4) ExpectData(t *testing.T, tcp *TCP, payload *Payload, timeout time.Duration) (Layers, error)
- func (conn *TCPIPv4) ExpectNextData(t *testing.T, tcp *TCP, payload *Payload, timeout time.Duration) (Layers, error)
- func (conn *TCPIPv4) LocalAddr(t *testing.T) *unix.SockaddrInet4
- func (conn *TCPIPv4) LocalSeqNum(t *testing.T) *seqnum.Value
- func (conn *TCPIPv4) RemoteSeqNum(t *testing.T) *seqnum.Value
- func (conn *TCPIPv4) Send(t *testing.T, tcp TCP, additionalLayers ...Layer)
- func (conn *TCPIPv4) SynAck(t *testing.T) *TCP
- type TCPIPv6
- type UDP
- type UDPIPv4
- func (conn *UDPIPv4) Expect(t *testing.T, udp UDP, timeout time.Duration) (*UDP, error)
- func (conn *UDPIPv4) ExpectData(t *testing.T, udp UDP, payload Payload, timeout time.Duration) (Layers, error)
- func (conn *UDPIPv4) LocalAddr(t *testing.T) *unix.SockaddrInet4
- func (conn *UDPIPv4) Send(t *testing.T, udp UDP, additionalLayers ...Layer)
- func (conn *UDPIPv4) SendFrame(t *testing.T, overrideLayers Layers, additionalLayers ...Layer)
- func (conn *UDPIPv4) SendIP(t *testing.T, ip IPv4, udp UDP, additionalLayers ...Layer)
- func (conn *UDPIPv4) SrcPort(t *testing.T) uint16
- type UDPIPv6
- func (conn *UDPIPv6) Expect(t *testing.T, udp UDP, timeout time.Duration) (*UDP, error)
- func (conn *UDPIPv6) ExpectData(t *testing.T, udp UDP, payload Payload, timeout time.Duration) (Layers, error)
- func (conn *UDPIPv6) LocalAddr(t *testing.T, zoneID uint32) *unix.SockaddrInet6
- func (conn *UDPIPv6) Send(t *testing.T, udp UDP, additionalLayers ...Layer)
- func (conn *UDPIPv6) SendFrame(t *testing.T, overrideLayers Layers, additionalLayers ...Layer)
- func (conn *UDPIPv6) SendIPv6(t *testing.T, ip IPv6, udp UDP, additionalLayers ...Layer)
- func (conn *UDPIPv6) SrcPort(t *testing.T) uint16
Constants ¶
This section is empty.
Variables ¶
var ( // Native indicates that the test is being run natively. Native = false // RPCKeepalive is the gRPC keepalive. RPCKeepalive = 10 * time.Second )
Functions ¶
func Address ¶
Address is a helper routine that allocates a new net.IP value to store v and returns a pointer to it.
func Bool ¶
Bool is a helper routine that allocates a new bool value to store v and returns a pointer to it.
func GenerateRandomPayload ¶
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 ¶
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 Initialize ¶
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 ¶
SeqNumValue is a helper routine that allocates a new seqnum.Value value to store v and returns a pointer to it.
func TCPFlags ¶
TCPFlags is a helper routine that allocates a new header.TCPFlags value to store v and returns a pointer to it.
func Uint16 ¶
Uint16 is a helper routine that allocates a new uint16 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 ¶
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 (*DUT) Accept ¶
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 ¶
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 ¶
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 ¶
CloseWithErrno calls close on the DUT.
func (*DUT) Connect ¶
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 ¶
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 ¶
CreateListener makes a new TCP connection. If it fails, the test ends.
func (*DUT) GetSockName ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
SetNonBlocking will set O_NONBLOCK flag for fd if nonblocking is true, otherwise it will clear the flag.
func (*DUT) SetSockLingerOption ¶
SetSockLingerOption sets SO_LINGER socket option on the DUT.
func (*DUT) SetSockOpt ¶
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 ¶
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 ¶
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 ¶
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 ¶
ShutdownWithErrno calls shutdown on the DUT.
func (*DUT) Socket ¶
Socket calls socket on the DUT and returns the file descriptor. If socket fails on the DUT, the test ends.
func (*DUT) SocketWithErrno ¶
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.
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.
type Ether ¶
type Ether struct { LayerBase SrcAddr *tcpip.LinkAddress DstAddr *tcpip.LinkAddress Type *tcpip.NetworkProtocolNumber }
Ether can construct and match an ethernet encapsulation.
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.
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.
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 *net.IP DstAddr *net.IP Options *header.IPv4Options }
IPv4 can construct and match an IPv4 encapsulation.
type IPv4Conn ¶
type IPv4Conn struct {
Connection
}
IPv4Conn maintains the state for all the layers in a IPv4 connection.
type IPv6 ¶
type IPv6 struct { LayerBase TrafficClass *uint8 FlowLabel *uint32 PayloadLength *uint16 NextHeader *uint8 HopLimit *uint8 SrcAddr *net.IP DstAddr *net.IP }
IPv6 can construct and match an IPv6 encapsulation.
type IPv6Conn ¶
type IPv6Conn struct {
Connection
}
IPv6Conn maintains the state for all the layers in a IPv6 connection.
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.
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.
type Layers ¶
type Layers []Layer
Layers is an array of Layer and supports similar functions to 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 Sniffer ¶
type Sniffer struct {
// contains filtered or unexported fields
}
Sniffer can sniff raw packets on the wire.
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.
type TCPIPv4 ¶
type TCPIPv4 struct {
Connection
}
TCPIPv4 maintains the state for all the layers in a TCP/IPv4 connection.
func (*TCPIPv4) Connect ¶
Connect performs a TCP 3-way handshake. The input Connection should have a final TCP Layer.
func (*TCPIPv4) ConnectWithOptions ¶
ConnectWithOptions performs a TCP 3-way handshake with given TCP options. The input Connection should have a final TCP Layer.
func (*TCPIPv4) Expect ¶
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 ¶
LocalSeqNum returns the next sequence number to send from the testbench.
func (*TCPIPv4) RemoteSeqNum ¶
RemoteSeqNum returns the next expected sequence number from the DUT.
type TCPIPv6 ¶
type TCPIPv6 struct {
Connection
}
TCPIPv6 maintains the state for all the layers in a TCP/IPv6 connection.
type UDPIPv4 ¶
type UDPIPv4 struct {
Connection
}
UDPIPv4 maintains the state for all the layers in a UDP/IPv4 connection.
func (*UDPIPv4) Expect ¶
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 ¶
Send sends a packet with reasonable defaults, potentially overriding the UDP layer and adding additionLayers.
func (*UDPIPv4) SendFrame ¶
SendFrame sends a frame on the wire and updates the state of all layers.
type UDPIPv6 ¶
type UDPIPv6 struct {
Connection
}
UDPIPv6 maintains the state for all the layers in a UDP/IPv6 connection.
func (*UDPIPv6) Expect ¶
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) Send ¶
Send sends a packet with reasonable defaults, potentially overriding the UDP layer and adding additionLayers.
func (*UDPIPv6) SendFrame ¶
SendFrame sends a frame on the wire and updates the state of all layers.