Newer
Older
)
var maxUint32 = ^uint32(0)
// pathIDManager manages BGP path identifiers for add-path. This is no thread safe (and doesn't need to be).
type pathIDManager struct {
}
func newPathIDManager() *pathIDManager {
return &pathIDManager{
func (fm *pathIDManager) addPath(p *route.Path) (uint32, error) {
hash := p.BGPPath.ComputeHash()
if _, exists := fm.idByPath[hash]; exists {
id := fm.idByPath[hash]
if fm.used == maxUint32 {
return 0, fmt.Errorf("Out of path IDs")
}
fm.last++
for {
if _, exists := fm.ids[fm.last]; exists {
fm.last++
continue
}
break
}
func (fm *pathIDManager) releasePath(p *route.Path) (uint32, error) {
hash := p.BGPPath.ComputeHash()
if _, exists := fm.idByPath[hash]; !exists {
return 0, fmt.Errorf("ID not found for path: %s", p.Print())
delete(fm.ids, fm.idByPath[hash])
delete(fm.idByPath, hash)