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 ¶
- type ControlMessage
- type Report
- type Tester
- func (t *Tester) Close() error
- func (t *Tester) IPv4PacketConn() *ipv4.PacketConn
- func (t *Tester) IPv6PacketConn() *ipv6.PacketConn
- func (t *Tester) Probe(b []byte, cm *ControlMessage, ip net.IP, ifi *net.Interface) error
- func (t Tester) Report() <-chan Report
- func (t Tester) StartReport()
- func (t Tester) StopReport()
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 ¶
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) 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 ¶
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.