Exemple #1
0
func (d destinations) Less(i, j int) bool {
	switch d[i].routeFamily {
	case bgp.RF_FS_IPv4_UC, bgp.RF_FS_IPv6_UC, bgp.RF_FS_IPv4_VPN, bgp.RF_FS_IPv6_VPN, bgp.RF_FS_L2_VPN:
		var s, t *bgp.FlowSpecNLRI
		switch d[i].routeFamily {
		case bgp.RF_FS_IPv4_UC:
			s = &d[i].nlri.(*bgp.FlowSpecIPv4Unicast).FlowSpecNLRI
			t = &d[j].nlri.(*bgp.FlowSpecIPv4Unicast).FlowSpecNLRI
		case bgp.RF_FS_IPv6_UC:
			s = &d[i].nlri.(*bgp.FlowSpecIPv6Unicast).FlowSpecNLRI
			t = &d[j].nlri.(*bgp.FlowSpecIPv6Unicast).FlowSpecNLRI
		case bgp.RF_FS_IPv4_VPN:
			s = &d[i].nlri.(*bgp.FlowSpecIPv4VPN).FlowSpecNLRI
			t = &d[j].nlri.(*bgp.FlowSpecIPv4VPN).FlowSpecNLRI
		case bgp.RF_FS_IPv6_VPN:
			s = &d[i].nlri.(*bgp.FlowSpecIPv6VPN).FlowSpecNLRI
			t = &d[j].nlri.(*bgp.FlowSpecIPv6VPN).FlowSpecNLRI
		case bgp.RF_FS_L2_VPN:
			s = &d[i].nlri.(*bgp.FlowSpecL2VPN).FlowSpecNLRI
			t = &d[j].nlri.(*bgp.FlowSpecL2VPN).FlowSpecNLRI
		}
		if r, _ := bgp.CompareFlowSpecNLRI(s, t); r >= 0 {
			return true
		} else {
			return false
		}
	default:
		strings := sort.StringSlice{d[i].nlri.String(), d[j].nlri.String()}
		return strings.Less(0, 1)
	}
}
Exemple #2
0
func (p paths) Less(i, j int) bool {
	if p[i].Nlri.String() == p[j].Nlri.String() {
		if p[i].Best {
			return true
		}
	}
	strings := sort.StringSlice{cidr2prefix(p[i].Nlri.String()),
		cidr2prefix(p[j].Nlri.String())}
	return strings.Less(0, 1)
}
Exemple #3
0
// Less is part of sort.Interface. It is implemented by calling the "by" closure in the sorter.
func (s sortedVoices) Less(i, j int) bool {
	var strs sort.StringSlice = []string{
		s[i].instrument.Name(),
		s[j].instrument.Name(),
	}

	return strs.Less(0, 1)
	// sort.Strings(a)

}
Exemple #4
0
func (s *SortByNoiseAndText) Less(i, j int) bool {
	if s.items[i].Noise < s.items[j].Noise {
		return false
	} else if s.items[i].Noise > s.items[j].Noise {
		return true
	} else if len(s.items[i].Runes) < len(s.items[j].Runes) {
		return false
	} else if len(s.items[i].Runes) > len(s.items[j].Runes) {
		return true
	} else {
		ss := sort.StringSlice{s.items[i].Name, s.items[j].Name}
		return ss.Less(0, 1)
	}
}
Exemple #5
0
func (p peers) Less(i, j int) bool {
	p1 := p[i].Conf.RemoteIp
	p2 := p[j].Conf.RemoteIp
	p1Isv4 := p1.To4() != nil
	p2Isv4 := p2.To4() != nil
	if p1Isv4 != p2Isv4 {
		if p1Isv4 {
			return true
		}
		return false
	}
	addrlen := 128
	if p1Isv4 {
		addrlen = 32
	}
	strings := sort.StringSlice{cidr2prefix(fmt.Sprintf("%s/%d", p1.String(), addrlen)),
		cidr2prefix(fmt.Sprintf("%s/%d", p2.String(), addrlen))}
	return strings.Less(0, 1)
}
Exemple #6
0
func (p peers) Less(i, j int) bool {
	p1 := p[i].Conf.RemoteIp
	p2 := p[j].Conf.RemoteIp
	p1Isv4 := !strings.Contains(p1, ":")
	p2Isv4 := !strings.Contains(p2, ":")
	if p1Isv4 != p2Isv4 {
		if p1Isv4 {
			return true
		}
		return false
	}
	addrlen := 128
	if p1Isv4 {
		addrlen = 32
	}
	strings := sort.StringSlice{cidr2prefix(fmt.Sprintf("%s/%d", p1, addrlen)),
		cidr2prefix(fmt.Sprintf("%s/%d", p2, addrlen))}
	return strings.Less(0, 1)
}
Exemple #7
0
func (n neighbors) Less(i, j int) bool {
	p1 := n[i].Config.NeighborAddress
	p2 := n[j].Config.NeighborAddress
	p1Isv4 := !strings.Contains(p1, ":")
	p2Isv4 := !strings.Contains(p2, ":")
	if p1Isv4 != p2Isv4 {
		if p1Isv4 {
			return true
		}
		return false
	}
	addrlen := 128
	if p1Isv4 {
		addrlen = 32
	}
	strings := sort.StringSlice{cidr2prefix(fmt.Sprintf("%s/%d", p1, addrlen)),
		cidr2prefix(fmt.Sprintf("%s/%d", p2, addrlen))}
	return strings.Less(0, 1)
}
Exemple #8
0
func (r roas) Less(i, j int) bool {
	strings := sort.StringSlice{cidr2prefix(fmt.Sprintf("%s/%d", r[i].Prefix, r[i].Prefixlen)),
		cidr2prefix(fmt.Sprintf("%s/%d", r[j].Prefix, r[j].Prefixlen))}
	return strings.Less(0, 1)
}
func (t tries) Less(i, j int) bool {
	strings := sort.StringSlice{string(t[i].prefix), string(t[j].prefix)}
	return strings.Less(0, 1)
}
Exemple #10
0
func (s *SortByText) Less(i, j int) bool {
	ss := sort.StringSlice{s.items[i].Name, s.items[j].Name}
	return ss.Less(0, 1)
}