twamp

package module
v0.0.0-...-5fddf96 Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2022 License: MIT Imports: 17 Imported by: 4

README

twamp

TWAMP client for go

Client Library Synopsis

	c := twamp.NewClient()
	connection, err := c.Connect("10.1.1.200:862")
	if err != nil {
		log.Fatal(err)
	}

	session, err := connection.CreateSession(
		twamp.TwampSessionConfig{
			ReceiverPort: 6666,
			SenderPort:   6666,
			Timeout:      1,
			Padding:      100,
			TOS:          twamp.EF,
		},
	)
	if err != nil {
		log.Fatal(err)
	}

	test, err := session.CreateTest()
	if err != nil {
		log.Fatal(err)
	}

	count := 2000
	results := test.RunMultiple(count, func(result *twamp.TwampResults) {
		fmt.Printf("%.2f  \r", float64(result.SenderSeqNum)/float64(count)*100.0)
	})
	if err != nil {
		log.Fatal("%v", err)
	}

	log.Printf("Stat: %+v\n", *results.Stat)
	session.Stop()
	connection.Close()

TWAMP ping command line utility

CLI Usage Message
sigsegv:twamp tcaine$ ./twamp --help
Usage of ./bin/twamp-client:
  -count uint
        Number of requests to send (0..18446744073709551615 packets, 0 being continuous) (default 5)
  -interval float
        Delay between TWAMP-test requests (seconds). For sub-second intervals, use floating points (default 1)
  -mode string
        Mode of operation (ping, json) (default "ping")
  -port int
        UDP port to send request packets (default 6666)
  -rapid
        Send requests as rapidly as possible (default count of 5, ignores interval and sends next packet as soon we have a response/timeout)
  -remote-port int
        Remote host port (default 862)
  -size int
        Size of request packets (0..65468 bytes) (default 42)
  -timeout int
        Maximum wait time for a response for the last packet (seconds). If rapid is set, this is a timeout for every packet (default 1)
  -tos int
        IP type-of-service value (0..255)
Twamp Ping
sigsegv:twamp tcaine$ ./twamp 10.1.1.200
TWAMP PING 10.1.1.200: 56 data bytes
56 bytes from 10.1.1.200: send_seq=0 refl_seq=0 ttl=250 time=45.252 ms
56 bytes from 10.1.1.200: send_seq=1 refl_seq=1 ttl=250 time=484.722 ms
56 bytes from 10.1.1.200: send_seq=2 refl_seq=2 ttl=250 time=134.527 ms
56 bytes from 10.1.1.200: send_seq=2 refl_seq=2 ttl=250 time=136.527 ms (DUP!)
56 bytes from 10.1.1.200: send_seq=3 refl_seq=3 ttl=250 time=41.005 ms
56 bytes from 10.1.1.200: send_seq=4 refl_seq=4 ttl=250 time=46.791 ms
--- 10.1.1.200 twamp ping statistics ---
5 packets transmitted, 5 packets received, +1 duplicates, 0.0% packet loss
round-trip min/avg/max/stddev = 41.005/150.459/484.722/190.907 ms
Twamp Rapid Ping
sigsegv:twamp tcaine$ ./twamp --count=100 --rapid 10.1.1.200 
TWAMP PING 10.1.1.200: 56 data bytes
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
--- 10.1.1.200 twamp ping statistics ---
100 packets transmitted, 100 packets received, 0.0% packet loss
round-trip min/avg/max/stddev = 27.456/81.008/924.369/115.346 ms
Twamp Ping JSON
sigsegv:twamp tcaine$ ./twamp --count=5 --mode=json 10.1.1.200 | json_pp
{
   "stats" : {
      "tx" : 5,
      "stddev" : 61171928,
      "rx" : 5,
      "avg" : 104719892,
      "min" : 29052824,
      "loss" : 0,
      "dup" : 1,
      "max" : 155204310
   },
   "results" : [
      {
         "senderTimestamp" : "2016-12-12T21:12:13.475143032-08:00",
         "finishedTimestamp" : "2016-12-12T21:12:13.523426063-08:00",
         "seqnum" : 0,
         "receiveTimestamp" : "2016-12-12T21:12:14.982226191-08:00",
         "senderTTL" : 250,
         "errorEstimate" : 1,
         "timestamp" : "2016-12-12T21:12:14.982780242-08:00",
         "senderSeqnum" : 0,
         "senderErrorEstimate" : 257,
         "senderSize" : 56,
         "isDuplicate": false
      },
      {
         "senderTimestamp" : "2016-12-12T21:12:13.523434427-08:00",
         "finishedTimestamp" : "2016-12-12T21:12:13.678393972-08:00",
         "seqnum" : 1,
         "receiveTimestamp" : "2016-12-12T21:12:15.662510356-08:00",
         "senderTTL" : 250,
         "errorEstimate" : 1,
         "timestamp" : "2016-12-12T21:12:15.662776644-08:00",
         "senderSeqnum" : 1,
         "senderErrorEstimate" : 257,
         "senderSize" : 56,
         "isDuplicate": false
      },
      {
         "senderTimestamp" : "2016-12-12T21:12:13.678401499-08:00",
         "finishedTimestamp" : "2016-12-12T21:12:13.833605809-08:00",
         "seqnum" : 2,
         "receiveTimestamp" : "2016-12-12T21:12:15.774115081-08:00",
         "senderTTL" : 250,
         "errorEstimate" : 1,
         "timestamp" : "2016-12-12T21:12:15.774321239-08:00",
         "senderSeqnum" : 2,
         "senderErrorEstimate" : 257,
         "senderSize" : 56,
         "isDuplicate": false
      },
      {
         "senderTimestamp" : "2016-12-12T21:12:13.833613447-08:00",
         "finishedTimestamp" : "2016-12-12T21:12:13.862666271-08:00",
         "seqnum" : 3,
         "receiveTimestamp" : "2016-12-12T21:12:16.454055649-08:00",
         "senderTTL" : 250,
         "errorEstimate" : 1,
         "timestamp" : "2016-12-12T21:12:16.454300462-08:00",
         "senderSeqnum" : 3,
         "senderErrorEstimate" : 257,
         "senderSize" : 56,
         "isDuplicate": false
      },
      {
         "senderTimestamp" : "2016-12-12T21:12:13.833613447-08:00",
         "finishedTimestamp" : "2016-12-12T21:12:13.863126880-08:00",
         "seqnum" : 3,
         "receiveTimestamp" : "2016-12-12T21:12:16.454055649-08:00",
         "senderTTL" : 250,
         "errorEstimate" : 1,
         "timestamp" : "2016-12-12T21:12:16.454300462-08:00",
         "senderSeqnum" : 3,
         "senderErrorEstimate" : 257,
         "senderSize" : 56,
         "isDuplicate": true
      },
      {
         "senderTimestamp" : "2016-12-12T21:12:13.862672913-08:00",
         "finishedTimestamp" : "2016-12-12T21:12:13.998772663-08:00",
         "seqnum" : 4,
         "receiveTimestamp" : "2016-12-12T21:12:16.580967637-08:00",
         "senderTTL" : 250,
         "errorEstimate" : 1,
         "timestamp" : "2016-12-12T21:12:16.581173796-08:00",
         "senderSeqnum" : 4,
         "senderErrorEstimate" : 257,
         "senderSize" : 56,
         "isDuplicate": false
      }
   ]
}
sigsegv:twamp tcaine$ 

Documentation

Index

Constants

View Source
const (
	ModeUnspecified     = 0
	ModeUnauthenticated = 1
	ModeAuthenticated   = 2
	ModeEncypted        = 4
)

Security modes for TWAMP session.

View Source
const (
	OK                          = 0
	Failed                      = 1
	InternalError               = 2
	NotSupported                = 3
	PermanentResourceLimitation = 4
	TemporaryResourceLimitation = 5
)

TWAMP Accept Field Status Code

View Source
const (
	BE   = 0x00
	CS1  = 0x20
	AF11 = 0x28
	AF12 = 0x30
	AF13 = 0x38
	CS2  = 0x40
	AF21 = 0x48
	AF22 = 0x50
	AF23 = 0x58
	CS3  = 0x60
	AF31 = 0x68
	AF32 = 0x70
	AF33 = 0x78
	CS4  = 0x80
	AF41 = 0x88
	AF42 = 0x90
	AF43 = 0x98
	CS5  = 0xA0
	EF   = 0xB8
	CS6  = 0xC0
	CS7  = 0xE0
)

Variables

This section is empty.

Functions

func NewTimestamp

func NewTimestamp(twampTimestamp TwampTimestamp) time.Time

Types

type MeasurementPacket

type MeasurementPacket struct {
	Sequence            uint32
	Timestamp           TwampTimestamp
	ErrorEstimate       uint16
	MBZ                 uint16
	ReceiveTimeStamp    TwampTimestamp
	SenderSequence      uint32
	SenderTimeStamp     TwampTimestamp
	SenderErrorEstimate uint16
	Mbz                 uint16
	SenderTtl           byte
}

type PingResultStats

type PingResultStats struct {
	Min         time.Duration `json:"min"`
	Max         time.Duration `json:"max"`
	Avg         time.Duration `json:"avg"`
	StdDev      time.Duration `json:"stddev"`
	Transmitted uint64        `json:"tx"`
	Received    uint64        `json:"rx"`
	Loss        float64       `json:"loss"`
	Duplicates  uint64        `json:"dup"`
}

type PingResults

type PingResults struct {
	Results []*TwampResults  `json:"results"`
	Stat    *PingResultStats `json:"stats"`
}

type RequestTwSession

type RequestTwSession []byte

func (RequestTwSession) Encode

type TwampAcceptSession

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

func NewTwampAcceptSession

func NewTwampAcceptSession(buf bytes.Buffer) *TwampAcceptSession

type TwampClient

type TwampClient struct{}

func NewClient

func NewClient() *TwampClient

func (*TwampClient) Connect

func (c *TwampClient) Connect(hostname string) (*TwampConnection, error)

type TwampClientSetUpResponse

type TwampClientSetUpResponse struct {
	Mode     uint32
	KeyID    [80]byte
	Token    [64]byte
	ClientIV [16]byte
}

TWAMP client session negotiation message.

type TwampConnection

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

func NewTwampConnection

func NewTwampConnection(conn net.Conn) *TwampConnection

func (*TwampConnection) Close

func (c *TwampConnection) Close()

func (*TwampConnection) CreateSession

func (c *TwampConnection) CreateSession(config TwampSessionConfig) (*TwampSession, error)

func (*TwampConnection) GetConnection

func (c *TwampConnection) GetConnection() net.Conn

func (*TwampConnection) LocalAddr

func (c *TwampConnection) LocalAddr() net.Addr

func (*TwampConnection) RemoteAddr

func (c *TwampConnection) RemoteAddr() net.Addr

func (*TwampConnection) TestConnection

func (c *TwampConnection) TestConnection() error

type TwampConnectionError

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

func (*TwampConnectionError) Error

func (e *TwampConnectionError) Error() string

type TwampResults

type TwampResults struct {
	SeqNum              uint32    `json:"seqnum"`
	Timestamp           time.Time `json:"timestamp"`
	ErrorEstimate       uint16    `json:"errorEstimate"`
	ReceiveTimestamp    time.Time `json:"receiveTimestamp"`
	SenderSeqNum        uint32    `json:"senderSeqnum"`
	SenderTimestamp     time.Time `json:"senderTimestamp"`
	SenderErrorEstimate uint16    `json:"senderErrorEstimate"`
	SenderTTL           byte      `json:"senderTTL"`
	FinishedTimestamp   time.Time `json:"finishedTimestamp"`
	SenderSize          int       `json:"senderSize"`
	SenderPaddingSize   int       `json:"senderPaddingSize"`
	IsDuplicate         bool      `json:"isDuplicate"`
}

TWAMP test result timestamps have been normalized to UNIX epoch time.

func (*TwampResults) GetRTT

func (r *TwampResults) GetRTT() time.Duration

func (*TwampResults) GetWait

func (r *TwampResults) GetWait() time.Duration

func (*TwampResults) PrintResults

func (r *TwampResults) PrintResults()

type TwampServerGreeting

type TwampServerGreeting struct {
	Mode      uint32   // modes (4 bytes)
	Challenge [16]byte // challenge (16 bytes)
	Salt      [16]byte // salt (16 bytes)
	Count     uint32   // count (4 bytes)
}

TWAMP server greeting message.

type TwampServerStart

type TwampServerStart struct {
	Accept    byte
	ServerIV  [16]byte
	StartTime TwampTimestamp
}

type TwampSession

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

func (*TwampSession) CreateTest

func (s *TwampSession) CreateTest() (*TwampTest, error)

func (*TwampSession) GetConfig

func (s *TwampSession) GetConfig() TwampSessionConfig

func (*TwampSession) GetConnection

func (s *TwampSession) GetConnection() net.Conn

func (*TwampSession) GetTimeout

func (s *TwampSession) GetTimeout() int

func (*TwampSession) Stop

func (s *TwampSession) Stop()

func (*TwampSession) TestConnection

func (s *TwampSession) TestConnection() error

func (*TwampSession) Write

func (s *TwampSession) Write(buf []byte)

type TwampSessionConfig

type TwampSessionConfig struct {
	// According to RFC 4656, if Conf-Receiver is not set, Receiver Port
	// is the UDP port OWAMP-Test to which packets are
	// requested to be sent.
	ReceiverPort int
	// According to RFC 4656, if Conf-Sender is not set, Sender Port is the
	// UDP port from which OWAMP-Test packets will be sent.
	SenderPort int
	// According to RFC 4656, Padding length is the number of octets to be
	// appended to the normal OWAMP-Test packet (see more on
	// padding in discussion of OWAMP-Test).
	Padding int
	// According to RFC 4656, Timeout (or a loss threshold) is an interval of time
	// (expressed as a timestamp). A packet belonging to the test session
	// that is being set up by the current Request-Session command will
	// be considered lost if it is not received during Timeout seconds
	// after it is sent.
	Timeout int
	TOS     int
}

type TwampTest

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

TWAMP test connection used for running TWAMP tests.

func (*TwampTest) FormatJSON

func (t *TwampTest) FormatJSON(r *PingResults)

func (*TwampTest) GetConnection

func (t *TwampTest) GetConnection() *net.UDPConn

Get TWAMP Test UDP connection.

func (*TwampTest) GetLocalTestHost

func (t *TwampTest) GetLocalTestHost() string

Get the local IP address for the TWAMP control session.

func (*TwampTest) GetRemoteTestHost

func (t *TwampTest) GetRemoteTestHost() string

Get the remote IP address for the TWAMP control session.

func (*TwampTest) GetRemoteTestPort

func (t *TwampTest) GetRemoteTestPort() uint16

Get the remote TWAMP UDP port number.

func (*TwampTest) GetSession

func (t *TwampTest) GetSession() *TwampSession

Get the underlying TWAMP control session for the TWAMP test.

func (*TwampTest) GetTimeout

func (t *TwampTest) GetTimeout() int

Get the configured timeout from the underlying TWAMP control session.

func (*TwampTest) Ping

func (t *TwampTest) Ping(count uint64, interval time.Duration, done chan bool) (*PingResults, error)

func (*TwampTest) PingRapid

func (t *TwampTest) PingRapid(count uint64, done <-chan bool) (*PingResults, error)

Use a blocking ping, pinging as soon as a reply or timeout is hit. TODO listen for done signal even while waiting for a reply/timeout as opposed to having to check for the signal at the start of each iteration

func (*TwampTest) RemoteAddr

func (t *TwampTest) RemoteAddr() (*net.UDPAddr, error)

Get the remote TWAMP IP/UDP address.

func (*TwampTest) Reset

func (t *TwampTest) Reset() error

This can be called to stop the reply reader instantly because we have already read everything we want and don't want to block further reads until timeout is hit, or read from a new iteration utilizing the same session

func (*TwampTest) ReturnJSON

func (t *TwampTest) ReturnJSON(r *PingResults) string

func (*TwampTest) RunMultiple

func (t *TwampTest) RunMultiple(count uint64, callback TwampTestCallbackFunction, interval time.Duration, done <-chan bool) (*PingResults, error)

func (*TwampTest) RunSingle

func (t *TwampTest) RunSingle() (*TwampResults, error)

Run a single TWAMP test and return a pointer to the TwampResults.

func (*TwampTest) SetConnection

func (t *TwampTest) SetConnection(conn *net.UDPConn)

type TwampTestCallbackFunction

type TwampTestCallbackFunction func(result *TwampResults)

Function header called when a test package arrived back. Can be used to show some progress

type TwampTimestamp

type TwampTimestamp struct {
	Integer  uint32
	Fraction uint32
}

func NewTwampTimestamp

func NewTwampTimestamp(t time.Time) *TwampTimestamp

Converts a UNIX epoch time time.Time object into an RFC 1305 compliant time.

func (*TwampTimestamp) GetTime

func (t *TwampTimestamp) GetTime() time.Time

Return a time.Time object representing Unix Epoch time since January 1st, 1970.

func (*TwampTimestamp) String

func (t *TwampTimestamp) String() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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