connectivity

package
v1.11.0-cni-plu...-7acfd45 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2024 License: Apache-2.0, Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const BinaryName = "test-connection"

BinaryName is the name of the binary that the connectivity Check() executes

View Source
const ConnectionTypePing = "ping"
View Source
const ConnectionTypeStream = "stream"

Variables

View Source
var UnactivatedCheckers = set.New[*Checker]()

Functions

func HaveConnectivityTo

func HaveConnectivityTo(target ConnectionTarget, explicitPort ...uint16) types.GomegaMatcher

func IsMessagePartOfStream

func IsMessagePartOfStream(msg string) bool

Types

type CheckCmd

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

CheckCmd is exported solely for the sake of CheckOption and should not be use on its own

type CheckOption

type CheckOption func(cmd *CheckCmd)

CheckOption is the option format for Check()

func WithDuration

func WithDuration(duration time.Duration) CheckOption

func WithNamespacePath

func WithNamespacePath(nsPath string) CheckOption

func WithRecvLen

func WithRecvLen(l int) CheckOption

func WithSendLen

func WithSendLen(l int) CheckOption

func WithSourceIP

func WithSourceIP(ip string) CheckOption

WithSourceIP tell the check what source IP to use

func WithSourcePort

func WithSourcePort(port string) CheckOption

WithSourcePort tell the check what source port to use

func WithTimeout

func WithTimeout(t time.Duration) CheckOption

type Checker

type Checker struct {
	ReverseDirection bool
	Protocol         string // "tcp" or "udp"

	CheckSNAT       bool
	RetriesDisabled bool
	StaggerStartBy  time.Duration

	// OnFail, if set, will be called instead of ginkgo.Fail().  (Useful for testing the checker itself.)
	OnFail func(msg string)
	// contains filtered or unexported fields
}

ConnectivityChecker records a set of connectivity expectations and supports calculating the actual state of the connectivity between the given workloads. It is expected to be used like so:

var cc = &connectivity.Checker{}
cc.Expect(None, w[2], w[0], 1234)
cc.Expect(Some, w[1], w[0], 5678)
cc.Expect(Some, w[1], w[0], 4321, ExpectWithABC, ExpectWithXYZ)
cc.CheckConnectivity()

func (*Checker) ActualConnectivity

func (c *Checker) ActualConnectivity(isARetry bool) ([]*Result, []string)

ActualConnectivity calculates the current connectivity for all the expected paths. It returns a slice containing one response for each attempted check (or nil if the check failed) along with a same-length slice containing a pretty-printed description of the check and its result.

func (*Checker) CheckConnectivity

func (c *Checker) CheckConnectivity(opts ...interface{})

func (*Checker) CheckConnectivityOffset

func (c *Checker) CheckConnectivityOffset(offset int, opts ...interface{})

func (*Checker) CheckConnectivityPacketLoss

func (c *Checker) CheckConnectivityPacketLoss(opts ...interface{})

func (*Checker) CheckConnectivityWithTimeout

func (c *Checker) CheckConnectivityWithTimeout(timeout time.Duration, opts ...interface{})

func (*Checker) CheckConnectivityWithTimeoutOffset

func (c *Checker) CheckConnectivityWithTimeoutOffset(callerSkip int, timeout time.Duration, opts ...interface{})

func (*Checker) Expect

func (c *Checker) Expect(expected Expected,
	from ConnectionSource, to ConnectionTarget, opts ...ExpectationOption)

Expect asserts existing connectivity between a ConnectionSource and ConnectionTarget with details configurable with ExpectationOption(s). This is a super set of ExpectSome()

func (*Checker) ExpectLoss

func (c *Checker) ExpectLoss(from ConnectionSource, to ConnectionTarget,
	duration time.Duration, maxPacketLossPercent float64, maxPacketLossNumber int, explicitPort ...uint16)

func (*Checker) ExpectNone

func (c *Checker) ExpectNone(from ConnectionSource, to ConnectionTarget, explicitPort ...uint16)

func (*Checker) ExpectSNAT

func (c *Checker) ExpectSNAT(from ConnectionSource, srcIP string, to ConnectionTarget, explicitPort ...uint16)

func (*Checker) ExpectSome

func (c *Checker) ExpectSome(from ConnectionSource, to ConnectionTarget, explicitPort ...uint16)

func (*Checker) ExpectedConnectivityPretty

func (c *Checker) ExpectedConnectivityPretty() []string

ExpectedConnectivityPretty returns one string per recorded expectation in order, encoding the expected connectivity in similar format used by ActualConnectivity().

func (*Checker) ResetExpectations

func (c *Checker) ResetExpectations()

type CheckerOpt

type CheckerOpt func(*Checker)

CheckerOpt is an option to CheckConnectivity()

func CheckWithBeforeRetry

func CheckWithBeforeRetry(f func()) CheckerOpt

CheckWithBeforeRetry sets a function executed after an attempt failed and before we retry.

func CheckWithDescription

func CheckWithDescription(desc string) CheckerOpt

CheckWithDescription sets a description of a failure.

func CheckWithFinalTest

func CheckWithFinalTest(f func() error) CheckerOpt

func CheckWithInit

func CheckWithInit(f func()) CheckerOpt

type ConnConfig

type ConnConfig struct {
	ConnType string
	ConnID   string
}

func (ConnConfig) GetTestMessage

func (cc ConnConfig) GetTestMessage(sequence int) Request

Assembly a test message.

func (ConnConfig) GetTestMessageSequence

func (cc ConnConfig) GetTestMessageSequence(msg string) (int, error)

Extract sequence number from test message.

type ConnectionSource

type ConnectionSource interface {
	PreRetryCleanup(ip, port, protocol string, opts ...CheckOption)
	CanConnectTo(ip, port, protocol string, opts ...CheckOption) *Result
	SourceName() string
	SourceIPs() []string
}

type ConnectionTarget

type ConnectionTarget interface {
	ToMatcher(explicitPort ...uint16) *Matcher
}

type ExpPacketLoss

type ExpPacketLoss struct {
	Duration   time.Duration // how long test will run
	MaxPercent float64       // 10 means 10%. -1 means field not valid.
	MaxNumber  int           // 10 means 10 packets. -1 means field not valid.
}

type Expectation

type Expectation struct {
	From               ConnectionSource // Workload or Container
	To                 *Matcher         // Workload or IP, + port
	Expected           Expected
	ExpSrcIPs          []string
	ExpectedPacketLoss ExpPacketLoss

	ErrorStr string
	// contains filtered or unexported fields
}

func (Expectation) DestIP

func (e Expectation) DestIP() string

func (Expectation) Matches

func (e Expectation) Matches(response *Result, checkSNAT bool) bool

type ExpectationOption

type ExpectationOption func(e *Expectation)

func ExpectNoneWithError

func ExpectNoneWithError(ErrorStr string) ExpectationOption

func ExpectWithClientAdjustedMTU

func ExpectWithClientAdjustedMTU(from, to int) ExpectationOption

ExpectWithClientAdjustedMTU asserts that the connection MTU should change during the transfer

func ExpectWithIPVersion

func ExpectWithIPVersion(ipVersion int) ExpectationOption

func ExpectWithLoss

func ExpectWithLoss(duration time.Duration, maxPacketLossPercent float64, maxPacketLossNumber int) ExpectationOption

ExpectWithLoss asserts that the connection has a certain loss rate

func ExpectWithPorts

func ExpectWithPorts(ports ...uint16) ExpectationOption

func ExpectWithRecvLen

func ExpectWithRecvLen(l int) ExpectationOption

ExpectWithRecvLen asserts how much additional data on top of the original response should be received with success

func ExpectWithSendLen

func ExpectWithSendLen(l int) ExpectationOption

ExpectWithSendLen asserts how much additional data on top of the original requests should be sent with success

func ExpectWithSrcIPs

func ExpectWithSrcIPs(ips ...string) ExpectationOption

func ExpectWithSrcPort

func ExpectWithSrcPort(port uint16) ExpectationOption

type Expected

type Expected bool

Expected defines what connectivity expectations we can have

const (
	// None no connectivity is expected
	None Expected = false
	// Some some connectivity, possibly after retries is expected
	Some Expected = true
)

type MTUPair

type MTUPair struct {
	Start int
	End   int
}

MTUPair is a pair of MTU value recorded before and after data were transferred

type Matcher

type Matcher struct {
	IP, Port, TargetName, Protocol, IP6 string
}

func (*Matcher) FailureMessage

func (m *Matcher) FailureMessage(actual interface{}) (message string)

func (*Matcher) Match

func (m *Matcher) Match(actual interface{}) (success bool, err error)

func (*Matcher) NegatedFailureMessage

func (m *Matcher) NegatedFailureMessage(actual interface{}) (message string)

type PersistentConnection

type PersistentConnection struct {
	sync.Mutex

	RuntimeName         string
	Runtime             Runtime
	Name                string
	Protocol            string
	IP                  string
	Port                int
	SourcePort          int
	MonitorConnectivity bool
	NamespacePath       string
	Timeout             time.Duration
	// contains filtered or unexported fields
}

func (*PersistentConnection) LastPongTime

func (pc *PersistentConnection) LastPongTime() time.Time

func (*PersistentConnection) PongCount

func (pc *PersistentConnection) PongCount() int

func (*PersistentConnection) SinceLastPong

func (pc *PersistentConnection) SinceLastPong() time.Duration

func (*PersistentConnection) Start

func (pc *PersistentConnection) Start() error

func (*PersistentConnection) Stop

func (pc *PersistentConnection) Stop()

type Request

type Request struct {
	Timestamp    time.Time
	ID           string
	Payload      string
	SendSize     int
	ResponseSize int
}

func NewRequest

func NewRequest(payload string) Request

func (Request) Equal

func (req Request) Equal(oth Request) bool

type Response

type Response struct {
	Timestamp time.Time

	SourceAddr string
	ServerAddr string

	Request  Request
	ErrorStr string
}

func (*Response) SourceIP

func (r *Response) SourceIP() string

type Result

type Result struct {
	LastResponse Response
	Stats        Stats
	ClientMTU    MTUPair
}

func Check

func Check(cName, logMsg, ip, port, protocol string, opts ...CheckOption) *Result

Check executes the connectivity check

func (*Result) HasConnectivity

func (r *Result) HasConnectivity() bool

func (Result) PrintToStdout

func (r Result) PrintToStdout()

type Runtime

type Runtime interface {
	ExecMayFail(cmd ...string) error
}

Runtime abstracts *containers.Container to avoid import loops

type Stats

type Stats struct {
	RequestsSent      int
	ResponsesReceived int
}

func (Stats) Lost

func (s Stats) Lost() int

func (Stats) LostPercent

func (s Stats) LostPercent() float64

type TargetIP

type TargetIP string // Just so we can define methods on it...

func (TargetIP) ToMatcher

func (s TargetIP) ToMatcher(explicitPort ...uint16) *Matcher

type TargetIPv4AsIPv6

type TargetIPv4AsIPv6 string

func (TargetIPv4AsIPv6) ToMatcher

func (s TargetIPv4AsIPv6) ToMatcher(explicitPort ...uint16) *Matcher

Jump to

Keyboard shortcuts

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