ipoam

package module
v0.0.0-...-48ecf14 Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2019 License: BSD-2-Clause Imports: 12 Imported by: 0

README

Package ipoam implements helper functions for IP-layer Operations, Administration, and Maintenance (OAM) tools. See RFC 6291 and RFC 7276 for further information.

GoDoc Build Status Build status Go Report Card

Documentation

Overview

Package ipoam implements helper functions for IP-layer Operations, Administration, and Maintenance (OAM) tools. See RFC 6291 and RFC 7276 for further information.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ControlMessage

type ControlMessage struct {
	ID   int // ICMP echo identifier
	Seq  int // ICMP echo sequence number
	Port int // UDP destination port
}

A ControlMessage contains per packet basis probe options.

type Report

type Report struct {
	Error error         // on-link operation error
	Time  time.Time     // time packet received
	Src   net.IP        // source address on received packet
	ICMP  *icmp.Message // received ICMP message

	// Original datagram fields when ICMP is an error message.
	OrigHeader  interface{} // IP header, either ipv4.Header or ipv6.Header
	OrigPayload []byte      // IP payload

	// These fields may not be set when the tester is configured
	// to use non-privileged datagram-oriented ICMP endpoint.
	TC        int            // IPv4 TOS or IPv6 traffic-class on received packet
	Hops      int            // IPv4 TTL or IPv6 hop-limit on receievd packet
	Dst       net.IP         // destinaion address on received packet
	Interface *net.Interface // inbound interface on received packet
}

A Report represents a test report for IP-layer OAM.

type Tester

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

A Tester represents a tester for IP-layer OAM.

Example (LinkLocalMulticastConnectivityVerification)
package main

import (
	"log"
	"net"
	"os"
	"time"

	"github.com/mikioh/ipoam"
)

func main() {
	ipt, err := ipoam.NewTester("ip6:ipv6-icmp", "::")
	if err != nil {
		log.Fatal(err)
	}
	defer ipt.Close()
	var mifi *net.Interface
	for _, name := range []string{"lo0", "lo"} {
		ifi, err := net.InterfaceByName(name)
		if err != nil {
			continue
		}
		mifi = ifi
		break
	}
	cm := ipoam.ControlMessage{ID: os.Getpid() & 0xffff}
	for i := 0; i < 3; i++ {
		cm.Seq = i + 1
		if err := ipt.Probe([]byte("HELLO-R-U-THERE"), &cm, net.ParseIP("ff02::1"), mifi); err != nil {
			log.Println(err)
			continue
		}
		t := time.NewTimer(500 * time.Millisecond)
		select {
		case <-t.C:
			log.Println("timedout")
		case r := <-ipt.Report():
			if r.Error != nil {
				log.Println(r.Error)
			} else {
				log.Println(r.ICMP)
			}
		}
		t.Stop()
	}
}
Output:

Example (UnicastConnectivityVerification)
package main

import (
	"log"
	"net"
	"os"
	"time"

	"github.com/mikioh/ipoam"
)

func main() {
	ipt, err := ipoam.NewTester("ip4:icmp", "0.0.0.0")
	if err != nil {
		log.Fatal(err)
	}
	defer ipt.Close()
	cm := ipoam.ControlMessage{ID: os.Getpid() & 0xffff}
	for i, dst := range []string{"8.8.8.8", "8.8.4.4"} {
		cm.Seq = i + 1
		if err := ipt.Probe([]byte("HELLO-R-U-THERE"), &cm, net.ParseIP(dst), nil); err != nil {
			log.Println(err)
			continue
		}
		t := time.NewTimer(500 * time.Millisecond)
		select {
		case <-t.C:
			log.Println("timedout")
		case r := <-ipt.Report():
			if r.Error != nil {
				log.Println(r.Error)
			} else {
				log.Println(r.ICMP)
			}
		}
		t.Stop()
	}
}
Output:

Example (UnicastPathDiscovery)
package main

import (
	"log"
	"net"
	"time"

	"github.com/mikioh/ipoam"
)

func main() {
	ipt, err := ipoam.NewTester("udp4", "0.0.0.0:0")
	if err != nil {
		log.Fatal(err)
	}
	defer ipt.Close()
	cm := ipoam.ControlMessage{Port: 33434}
	for i := 1; i <= 3; i++ {
		ipt.IPv4PacketConn().SetTTL(i)
		if err := ipt.Probe([]byte("HELLO-R-U-THERE"), &cm, net.ParseIP("8.8.8.8"), nil); err != nil {
			log.Println(err)
			continue
		}
		t := time.NewTimer(500 * time.Millisecond)
		select {
		case <-t.C:
			log.Println("timedout")
		case r := <-ipt.Report():
			if r.Error != nil {
				log.Println(r.Error)
			} else {
				log.Println(r.ICMP)
			}
		}
		t.Stop()
	}
}
Output:

func NewTester

func NewTester(network, address string) (*Tester, error)

NewTester makes both maintenance and probe network connections and listens for incoming ICMP packets addressed to the address on the maintenance network connection. The network must specify a probe network. It must be "ip4:icmp", "ip4:1", "ip6:ipv6-icmp", "ip6:58", "udp", "udp4" or "udp6".

Examples:

NewTester("ip4:icmp", "0.0.0.0")
NewTester("udp", "0.0.0.0")
NewTester("ip6:58", "2001:db8::1")

func (*Tester) Close

func (t *Tester) Close() error

Close closes both the maintenance and probe network connections.

func (*Tester) IPv4PacketConn

func (t *Tester) IPv4PacketConn() *ipv4.PacketConn

IPv4PacketConn returns the ipv4.PacketConn of the probe network connection. It returns nil when t is not created as a tester using IPv4.

func (*Tester) IPv6PacketConn

func (t *Tester) IPv6PacketConn() *ipv6.PacketConn

IPv6PacketConn returns the ipv6.PacketConn of the probe network connection. It returns nil when t is not created as a tester using IPv6.

func (*Tester) Probe

func (t *Tester) Probe(b []byte, cm *ControlMessage, ip net.IP, ifi *net.Interface) error

Probe transmits a single probe packet to ip via ifi. Each call updates the internal receive packet filter on the maintenance network connection automatically.

func (Tester) Report

func (t Tester) Report() <-chan Report

Report returns the buffered test report channel.

func (Tester) StartReport

func (t Tester) StartReport()

StartReport enables emitting test reports.

func (Tester) StopReport

func (t Tester) StopReport()

StopReport disables emitting test reports.

Directories

Path Synopsis
cmd
ipoam
Command ipoam verifies IP-layer connectivity and discovers an IP-layer path like ping and traceroute commands.
Command ipoam verifies IP-layer connectivity and discovers an IP-layer path like ping and traceroute commands.

Jump to

Keyboard shortcuts

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