context

package
v0.0.0-...-7ea8bc4 Latest Latest
Warning

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

Go to latest
Published: Dec 21, 2017 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// StackAddr is the IPv4 address assigned to the stack
	StackAddr = "\x0a\x00\x00\x01"

	// StackPort is used as the listening port in tests for passive connects
	StackPort = 1234

	// TestAddr is the source address for packets sent to the stack via the
	// link layer endpoint
	TestAddr = "\x0a\x00\x00\x02"

	// TestPort is the TCP port used for packets sent to the stack via the link layer
	// endpoint
	TestPort = 4096
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Context

type Context struct {

	// IRS holds the initial sequence number in the SYN sent by endpoint in
	// case of an actice connect or the sequence number sent by the endpoint
	// in the SYN-ACK sent in response to a SYN when listening in passive
	// mode
	IRS seqnum.Value

	// Port holds the port bound by EP below in case of an active connect or
	// the listening port number in case of a passive connect
	Port uint16

	// EP is the test endpoint in the stack owned by this context. This endpoint
	// is used in various tests to either initiate an active context or is used
	// as a passive listening endpoint to accept inbound connections
	EP types.Endpoint

	// WQ is the wait queue associated with EP and is used to block for events
	WQ waiter.Queue
	// contains filtered or unexported fields
}

Context provides an initialized Network stack and a link layer endpoint for use in TCP tests

func New

func New(t *testing.T, mtu uint32) *Context

New allocations and initializes a test context containing a new stack and a link-layer endpoint

func (*Context) CheckNoPacket

func (c *Context) CheckNoPacket(errMsg string)

CheckNoPacket verifies that no packet is received for 1 second

func (*Context) CheckNoPacketTimeout

func (c *Context) CheckNoPacketTimeout(errMsg string, wait time.Duration)

CheckNoPacketTimeout verifies that no packet is received during the time specified by wait

func (*Context) Cleanup

func (c *Context) Cleanup()

Cleanup closes the context endpoint if required

func (*Context) CreateConnected

func (c *Context) CreateConnected(iss seqnum.Value, rcvWnd seqnum.Size, epRcvBuf *types.ReceiveBufferSizeOption)

CreateConnected creates a connected TCP endpoint

func (*Context) CreateConnectedWithRawOptions

func (c *Context) CreateConnectedWithRawOptions(iss seqnum.Value, rcvWnd seqnum.Size, epRcvBuf *types.ReceiveBufferSizeOption, options []byte)

CreateConnectedWithRawOptions creates a connected TCP endpoint and sends the specified option bytes as the Option field in initial SYN packet

It also sets the receive buffer for the endpoint to the specified value in epRcvBuf

func (*Context) GetPacket

func (c *Context) GetPacket() []byte

GetPacket reads a packet from the link layer endpoint and verifies that it is an IPv4 packet with the expected source and destination addresses. It will fail with an error if no packet is received for 2 seconds

func (*Context) PassiveConnectWithOptions

func (c *Context) PassiveConnectWithOptions(maxPayload, wndScale int, synOptions header.TCPSynOptions)

PassiveConnectionWithOptions initiates a new connectin (with the specified TCP options enabled) to the port on which the Context.ep is listening for new connections. It also validates that the SYN-ACK has the expected values for the enabled options.

NOTE: MSS is not a negotiated option and it can be asymmetric in each direction. This function uses the mayPayload to set the MSS to be sent to the peer on a connect and validates that the MSS in the SYN-ACK response is equal to the MTU - (tcphdr len + iphdr len)

wndScale is the expected window scale in the SYN-ACK and synOptions.WS is the value of the window scaling option to be sent in the SYN. If synOptions.WS > 0 then we send the WindowScale option

func (*Context) SendPacket

func (c *Context) SendPacket(payload []byte, h *Headers)

SendPacket builds and sends a TCP segment(with the provided payload and TCP headers) in an IPv4 packet via the link layer endpoint

func (*Context) Stack

func (c *Context) Stack() *stack.Stack

Stack returns a reference to the stack in the Context

type Headers

type Headers struct {
	// SrcPort holds the src port value to be used in the packet
	SrcPort uint16

	// DstPort holds the destination port value to be used in the packet
	DstPort uint16

	// SeqNum is the value of the sequence number field in the TCP header
	SeqNum seqnum.Value

	// AckNum represents the acknowledgement number fields in the TCP header
	AckNum seqnum.Value

	// Flags are the TCP flags in the TCP header
	Flags int

	// RcvWnd is the window to be advertised in the ReceiveWindow field of
	// the TCP header
	RcvWnd seqnum.Size

	// TCPOpts holds the options to be sent in the option field of the TCP
	// header
	TCPOpts []byte
}

Headers is used to represent the TCP header fields when building a new packet

Jump to

Keyboard shortcuts

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