udp

package
v0.0.0-...-f4dfc87 Latest Latest
Warning

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

Go to latest
Published: Sep 6, 2016 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const PACKET_MTU = 1500 // XXX: not including IP overhead..?
View Source
const PACKET_TTL uint8 = 64
View Source
const PAYLOAD_SIZE = 16 // XXX: or smaller with varint?
View Source
const PORT uint = 1337 // used as destination port
View Source
const SOURCE_PORT uint = 0
View Source
const SOURCE_PORT_BITS uint = 0

Variables

This section is empty.

Functions

This section is empty.

Types

type ID

type ID [8]byte

func (ID) String

func (self ID) String() string

type Packet

type Packet struct {
	SrcIP   net.IP
	SrcPort uint16
	DstIP   net.IP
	DstPort uint16

	PayloadSize uint
	Payload     Payload
}

func (*Packet) PackIP

func (self *Packet) PackIP() ([]byte, error)

Pack into an IP+UDP+Payload packet

type Payload

type Payload struct {
	// Chosen by the sender, kept the same for all consecutive packets in the same sequence.
	// The receiver requires this to be unique per sender for reliable sequence tracking.
	// Required since a sender may transmit from different randomized source addresses, possibly overlapping with other senders.
	ID ID

	// The sender sends packets with consective sequence numbers, starting from zero.
	// Used by the sender to count received/missed/reordered packets, per ID.
	Seq uint64
}

func (Payload) Pack

func (self Payload) Pack(dataSize uint) []byte

func (*Payload) Unpack

func (self *Payload) Unpack(buf []byte) error

type RandPort

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

func (*RandPort) Port

func (self *RandPort) Port() uint16

func (*RandPort) SetPort

func (self *RandPort) SetPort(port uint)

func (*RandPort) SetRandom

func (self *RandPort) SetRandom(bits uint)

type RateClock

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

func (*RateClock) Set

func (self *RateClock) Set(rate uint, count uint)

change running timer

func (*RateClock) Start

func (self *RateClock) Start(rate uint, count uint) chan time.Time

func (*RateClock) Stop

func (self *RateClock) Stop()

Stop running, closing the chan returned by Start()

type RateStats

type RateStats struct {
	SleepDuration time.Duration // total time slept
	UnderrunCount uint          // count of timing underruns (no sleep)
	Count         uint          // count of timing ticks
}

type Recv

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

func NewRecv

func NewRecv(config RecvConfig) (*Recv, error)

func (*Recv) Config

func (self *Recv) Config() *RecvConfig

func (*Recv) Run

func (self *Recv) Run() error

func (*Recv) StatsWriter

func (self *Recv) StatsWriter(statsWriter *stats.Writer) error

func (*Recv) String

func (self *Recv) String() string

type RecvConfig

type RecvConfig struct {
	ListenAddr string `long:"listen-addr" default:"0.0.0.0:1337"`
}

func (RecvConfig) Apply

func (self RecvConfig) Apply() (*Recv, error)

type RecvState

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

type RecvStats

type RecvStats struct {
	ID       ID            // from recv ID
	Time     time.Time     // stats were init/reset
	Duration time.Duration // stats were collected

	PacketTime   time.Time // time of most recent packet
	PacketStart  uint64    // stats for packets following this seq (non-inclusive)
	PacketSeq    uint64    // most recent packet
	PacketSize   uint      // total size of received packets
	PacketErrors uint      // invalid packets
	PacketCount  uint      // in-sequence packets
	PacketSkips  uint      // skipped in-sequence packets
	PacketDups   uint      // out-of-sequence packets
}

func (RecvStats) PacketLoss

func (self RecvStats) PacketLoss() float64

proportion of lost or reordered packets, not counting duplicates this ratio only applies when .Valid()

func (RecvStats) PacketWin

func (self RecvStats) PacketWin() float64

proportion of delivered packets, not counting reordered or duplicated packets this ratio only applies when .Valid()

func (RecvStats) StatsFields

func (self RecvStats) StatsFields() map[string]interface{}

func (RecvStats) StatsID

func (self RecvStats) StatsID() stats.ID

func (RecvStats) StatsTime

func (self RecvStats) StatsTime() time.Time

func (RecvStats) String

func (self RecvStats) String() string

func (RecvStats) Valid

func (self RecvStats) Valid() bool

check if we have any received packets to report on

type Send

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

func NewSend

func NewSend(config SendConfig) (*Send, error)

func (*Send) Config

func (self *Send) Config() config.Config

func (*Send) ConfigSub

func (self *Send) ConfigSub(configSub *config.Sub) error

pull runtime configuration from config source

func (*Send) Run

func (self *Send) Run() error

Generate a sequence of *Packet

Returns once complete, or error

func (*Send) StatsWriter

func (self *Send) StatsWriter(statsWriter *stats.Writer) error

func (*Send) Stop

func (self *Send) Stop()

func (*Send) String

func (self *Send) String() string

type SendConfig

type SendConfig struct {
	DestAddr       string `long:"dest-addr" value-name:"HOST:PORT" description:"Fixed destination address" required:"yes"`
	SourceNet      string `long:"source-net" value-name:"HOST/MASK" description:"Use raw IP socket with given randomized range of source addresses"`
	SourcePort     uint   `long:"source-port" value-name:"0-65535" description:"Use raw IP socket with given randomized source port"`
	SourcePortBits uint   `long:"source-port-bits" value-name:"0-16" description:"Randomize low-order bits of source-port"`

	ID    string `json:"id" long:"id"`       // 64-bit hex ID, or random
	Rate  uint   `json:"rate" long:"rate"`   // 0 - unrated
	Count uint   `json:"count" long:"count"` // 0 - infinite
	Size  uint   `json:"size" long:"size"`   // target size of UDP payload
}

func (SendConfig) Worker

func (self SendConfig) Worker() (worker.Worker, error)

type SendStats

type SendStats struct {
	ID    ID        // send id, to correlated with RecvStats
	Start time.Time // stats were reset
	Time  time.Time // stats were updated

	Config SendConfig
	Rate   RateStats
	Send   SockStats // Send.Bytes includes IP+UDP+Payload
}

func (SendStats) CalcRate

func (self SendStats) CalcRate() float64

func (SendStats) Duration

func (self SendStats) Duration() time.Duration

func (SendStats) RateError

func (self SendStats) RateError() float64

Return the actual rate vs configured rate as a proportional error, with 1.0 being the most accurate

func (SendStats) RateUtil

func (self SendStats) RateUtil() float64

Return rate-loop utilization between 0..1, with 1.0 being fully utilized (unable to keep up with rate)

func (SendStats) StatsFields

func (self SendStats) StatsFields() map[string]interface{}

func (SendStats) StatsID

func (self SendStats) StatsID() stats.ID

func (SendStats) StatsTime

func (self SendStats) StatsTime() time.Time

func (SendStats) String

func (self SendStats) String() string

type SerializableNetworkLayer

type SerializableNetworkLayer interface {
	gopacket.NetworkLayer
	gopacket.SerializableLayer
}

used for serializing packets with transport-layer checksums

type SockIP

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

type SockRecv

type SockRecv interface {
	// contains filtered or unexported methods
}

type SockSend

type SockSend interface {
	// contains filtered or unexported methods
}

type SockStats

type SockStats struct {
	Errors  uint
	Packets uint
	Bytes   uint // only includes Payload
}

type SockSyscall

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

type SockUDP

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

func (*SockUDP) String

func (self *SockUDP) String() string

Jump to

Keyboard shortcuts

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