Skip to content
Snippets Groups Projects
Commit bf0beb23 authored by Oliver Herms's avatar Oliver Herms
Browse files

Fixed add path path IDs

parent 4715900c
No related branches found
No related tags found
No related merge requests found
......@@ -41,7 +41,7 @@ func main() {
b.AddPeer(config.Peer{
AdminEnabled: true,
LocalAS: 65200,
LocalAS: 6695,
PeerAS: 65300,
PeerAddress: net.IP([]byte{169, 254, 200, 1}),
LocalAddress: net.IP([]byte{169, 254, 200, 0}),
......@@ -53,14 +53,14 @@ func main() {
AddPathSend: routingtable.ClientOptions{
MaxPaths: 10,
},
ImportFilter: filter.NewDrainFilter(),
ImportFilter: filter.NewAcceptAllFilter(),
ExportFilter: filter.NewAcceptAllFilter(),
RouteServerClient: true,
}, rib)
b.AddPeer(config.Peer{
AdminEnabled: true,
LocalAS: 65200,
LocalAS: 6695,
PeerAS: 65100,
PeerAddress: net.IP([]byte{169, 254, 100, 0}),
LocalAddress: net.IP([]byte{169, 254, 100, 1}),
......@@ -74,7 +74,7 @@ func main() {
},
AddPathRecv: true,
ImportFilter: filter.NewAcceptAllFilter(),
ExportFilter: filter.NewDrainFilter(),
ExportFilter: filter.NewAcceptAllFilter(),
RouteServerClient: true,
}, rib)
......
File moved
......@@ -82,6 +82,7 @@ func serializeAndSendUpdate(out io.Writer, update serializeAbleUpdate) error {
return nil
}
fmt.Printf("Sending Update: %v\n", updateBytes)
_, err = out.Write(updateBytes)
if err != nil {
return fmt.Errorf("Failed sending Update: %v", err)
......
......@@ -158,6 +158,10 @@ func (b *BGPPath) Print() string {
nh := uint32To4Byte(b.NextHop)
ret += fmt.Sprintf("\t\tNEXT HOP: %d.%d.%d.%d\n", nh[0], nh[1], nh[2], nh[3])
ret += fmt.Sprintf("\t\tMED: %d\n", b.MED)
ret += fmt.Sprintf("\t\tPath ID: %d\n", b.PathIdentifier)
ret += fmt.Sprintf("\t\tSource: %d\n", b.Source)
ret += fmt.Sprintf("\t\tCommunities: %s\n", b.Communities)
ret += fmt.Sprintf("\t\tLargeCommunities: %s\n", b.LargeCommunities)
return ret
}
......
......@@ -67,10 +67,12 @@ func (a *AdjRIBOut) AddPath(pfx bnet.Prefix, p *route.Path) error {
a.removePathsFromClients(pfx, oldPaths)
}
pathID, err := a.pathIDManager.getNewID()
fmt.Printf("Adding path: %s\n", p.Print())
pathID, err := a.pathIDManager.addPath(p)
if err != nil {
return fmt.Errorf("Unable to get path ID: %v", err)
}
fmt.Printf("New path ID: %d\n", pathID)
p.BGPPath.PathIdentifier = pathID
a.rt.AddPath(pfx, p)
......@@ -90,6 +92,11 @@ func (a *AdjRIBOut) RemovePath(pfx bnet.Prefix, p *route.Path) bool {
return false
}
p, reject := a.exportFilter.ProcessTerms(pfx, p)
if reject {
return false
}
a.mu.Lock()
defer a.mu.Unlock()
......@@ -99,7 +106,14 @@ func (a *AdjRIBOut) RemovePath(pfx bnet.Prefix, p *route.Path) bool {
}
a.rt.RemovePath(pfx, p)
a.pathIDManager.releaseID(p.BGPPath.PathIdentifier)
pathID, err := a.pathIDManager.releasePath(p)
if err != nil {
log.Warningf("Unable to release path: %v", err)
return true
}
p = p.Copy()
p.BGPPath.PathIdentifier = pathID
a.removePathFromClients(pfx, p)
return true
}
......
......@@ -2,24 +2,34 @@ package adjRIBOut
import (
"fmt"
"github.com/bio-routing/bio-rd/route"
)
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 {
ids map[uint32]struct{}
last uint32
used uint32
ids map[uint32]uint64
idByPath map[route.BGPPath]uint32
last uint32
used uint32
}
func newPathIDManager() *pathIDManager {
return &pathIDManager{
ids: make(map[uint32]struct{}),
ids: make(map[uint32]uint64),
idByPath: make(map[route.BGPPath]uint32),
}
}
func (fm *pathIDManager) getNewID() (uint32, error) {
func (fm *pathIDManager) addPath(p *route.Path) (uint32, error) {
if _, exists := fm.idByPath[*p.BGPPath]; exists {
id := fm.idByPath[*p.BGPPath]
fm.ids[id]++
return id, nil
}
if fm.used == maxUint32 {
return 0, fmt.Errorf("Out of path IDs")
}
......@@ -33,15 +43,24 @@ func (fm *pathIDManager) getNewID() (uint32, error) {
break
}
ret := fm.last
fm.idByPath[*p.BGPPath] = fm.last
fm.ids[fm.last] = 1
fm.used++
return ret, nil
return fm.last, nil
}
func (fm *pathIDManager) releaseID(id uint32) {
if _, exists := fm.ids[id]; exists {
delete(fm.ids, id)
fm.used--
func (fm *pathIDManager) releasePath(p *route.Path) (uint32, error) {
if _, exists := fm.idByPath[*p.BGPPath]; !exists {
return 0, fmt.Errorf("ID not found for path: %s", p.Print())
}
id := fm.idByPath[*p.BGPPath]
fm.ids[id]--
if fm.ids[id] == 0 {
delete(fm.ids, fm.idByPath[*p.BGPPath])
delete(fm.idByPath, *p.BGPPath)
}
return id, nil
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment