Esempio n. 1
0
func BenchmarkIPv4ComparePrefix(b *testing.B) {
	p1, _ := ipaddr.NewPrefix(net.ParseIP("192.168.1.0"), 24)
	p2, _ := ipaddr.NewPrefix(net.ParseIP("192.168.2.0"), 24)
	for i := 0; i < b.N; i++ {
		ipaddr.ComparePrefix(p1, p2)
	}
}
Esempio n. 2
0
func BenchmarkIPv6ComparePrefix(b *testing.B) {
	p1, _ := ipaddr.NewPrefix(net.ParseIP("2001:db8:f001:f002::"), 64)
	p2, _ := ipaddr.NewPrefix(net.ParseIP("2001:db8:f001:f003::"), 64)
	for i := 0; i < b.N; i++ {
		ipaddr.ComparePrefix(p1, p2)
	}
}
Esempio n. 3
0
func (ps byPrefixLen) Less(i, j int) bool {
	if ps[i].Len() < ps[j].Len() {
		return true
	} else if ps[i].Len() > ps[j].Len() {
		return false
	}
	if ipaddr.ComparePrefix(ps[i], ps[j]) < 0 {
		return true
	}
	return false
}
Esempio n. 4
0
func TestComparePrefix(t *testing.T) {
	for i, tt := range comparePrefixTests {
		var nn []*net.IPNet
		for _, s := range tt.prefixes {
			_, n, err := net.ParseCIDR(s)
			if err != nil {
				t.Fatalf("net.ParseCIDR failed: %v", err)
			}
			nn = append(nn, n)
		}
		var ps []ipaddr.Prefix
		for _, n := range nn {
			prefixLen, _ := n.Mask.Size()
			p, err := ipaddr.NewPrefix(n.IP, prefixLen)
			if err != nil {
				t.Fatalf("ipaddr.NewPrefix failed: %v", err)
			}
			ps = append(ps, p)
		}
		if n := ipaddr.ComparePrefix(ps[0], ps[1]); n != tt.ncmp {
			t.Fatalf("#%v: got %v; expected %v", i, n, tt.ncmp)
		}
	}
}
Esempio n. 5
0
func (ps byAddress) Less(i, j int) bool {
	if ipaddr.ComparePrefix(ps[i], ps[j]) < 0 {
		return true
	}
	return false
}
Esempio n. 6
0
func (h *prefixHeap) Less(i, j int) bool {
	return ipaddr.ComparePrefix((*h)[i], (*h)[j]) < 0
}