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() { ...@@ -41,7 +41,7 @@ func main() {
b.AddPeer(config.Peer{ b.AddPeer(config.Peer{
AdminEnabled: true, AdminEnabled: true,
LocalAS: 65200, LocalAS: 6695,
PeerAS: 65300, PeerAS: 65300,
PeerAddress: net.IP([]byte{169, 254, 200, 1}), PeerAddress: net.IP([]byte{169, 254, 200, 1}),
LocalAddress: net.IP([]byte{169, 254, 200, 0}), LocalAddress: net.IP([]byte{169, 254, 200, 0}),
...@@ -53,14 +53,14 @@ func main() { ...@@ -53,14 +53,14 @@ func main() {
AddPathSend: routingtable.ClientOptions{ AddPathSend: routingtable.ClientOptions{
MaxPaths: 10, MaxPaths: 10,
}, },
ImportFilter: filter.NewDrainFilter(), ImportFilter: filter.NewAcceptAllFilter(),
ExportFilter: filter.NewAcceptAllFilter(), ExportFilter: filter.NewAcceptAllFilter(),
RouteServerClient: true, RouteServerClient: true,
}, rib) }, rib)
b.AddPeer(config.Peer{ b.AddPeer(config.Peer{
AdminEnabled: true, AdminEnabled: true,
LocalAS: 65200, LocalAS: 6695,
PeerAS: 65100, PeerAS: 65100,
PeerAddress: net.IP([]byte{169, 254, 100, 0}), PeerAddress: net.IP([]byte{169, 254, 100, 0}),
LocalAddress: net.IP([]byte{169, 254, 100, 1}), LocalAddress: net.IP([]byte{169, 254, 100, 1}),
...@@ -74,7 +74,7 @@ func main() { ...@@ -74,7 +74,7 @@ func main() {
}, },
AddPathRecv: true, AddPathRecv: true,
ImportFilter: filter.NewAcceptAllFilter(), ImportFilter: filter.NewAcceptAllFilter(),
ExportFilter: filter.NewDrainFilter(), ExportFilter: filter.NewAcceptAllFilter(),
RouteServerClient: true, RouteServerClient: true,
}, rib) }, rib)
......
File moved
...@@ -82,6 +82,7 @@ func serializeAndSendUpdate(out io.Writer, update serializeAbleUpdate) error { ...@@ -82,6 +82,7 @@ func serializeAndSendUpdate(out io.Writer, update serializeAbleUpdate) error {
return nil return nil
} }
fmt.Printf("Sending Update: %v\n", updateBytes)
_, err = out.Write(updateBytes) _, err = out.Write(updateBytes)
if err != nil { if err != nil {
return fmt.Errorf("Failed sending Update: %v", err) return fmt.Errorf("Failed sending Update: %v", err)
......
...@@ -158,6 +158,10 @@ func (b *BGPPath) Print() string { ...@@ -158,6 +158,10 @@ func (b *BGPPath) Print() string {
nh := uint32To4Byte(b.NextHop) 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\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\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 return ret
} }
......
...@@ -67,10 +67,12 @@ func (a *AdjRIBOut) AddPath(pfx bnet.Prefix, p *route.Path) error { ...@@ -67,10 +67,12 @@ func (a *AdjRIBOut) AddPath(pfx bnet.Prefix, p *route.Path) error {
a.removePathsFromClients(pfx, oldPaths) 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 { if err != nil {
return fmt.Errorf("Unable to get path ID: %v", err) return fmt.Errorf("Unable to get path ID: %v", err)
} }
fmt.Printf("New path ID: %d\n", pathID)
p.BGPPath.PathIdentifier = pathID p.BGPPath.PathIdentifier = pathID
a.rt.AddPath(pfx, p) a.rt.AddPath(pfx, p)
...@@ -90,6 +92,11 @@ func (a *AdjRIBOut) RemovePath(pfx bnet.Prefix, p *route.Path) bool { ...@@ -90,6 +92,11 @@ func (a *AdjRIBOut) RemovePath(pfx bnet.Prefix, p *route.Path) bool {
return false return false
} }
p, reject := a.exportFilter.ProcessTerms(pfx, p)
if reject {
return false
}
a.mu.Lock() a.mu.Lock()
defer a.mu.Unlock() defer a.mu.Unlock()
...@@ -99,7 +106,14 @@ func (a *AdjRIBOut) RemovePath(pfx bnet.Prefix, p *route.Path) bool { ...@@ -99,7 +106,14 @@ func (a *AdjRIBOut) RemovePath(pfx bnet.Prefix, p *route.Path) bool {
} }
a.rt.RemovePath(pfx, p) 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) a.removePathFromClients(pfx, p)
return true return true
} }
......
...@@ -2,24 +2,34 @@ package adjRIBOut ...@@ -2,24 +2,34 @@ package adjRIBOut
import ( import (
"fmt" "fmt"
"github.com/bio-routing/bio-rd/route"
) )
var maxUint32 = ^uint32(0) var maxUint32 = ^uint32(0)
// pathIDManager manages BGP path identifiers for add-path. This is no thread safe (and doesn't need to be). // pathIDManager manages BGP path identifiers for add-path. This is no thread safe (and doesn't need to be).
type pathIDManager struct { type pathIDManager struct {
ids map[uint32]struct{} ids map[uint32]uint64
last uint32 idByPath map[route.BGPPath]uint32
used uint32 last uint32
used uint32
} }
func newPathIDManager() *pathIDManager { func newPathIDManager() *pathIDManager {
return &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 { if fm.used == maxUint32 {
return 0, fmt.Errorf("Out of path IDs") return 0, fmt.Errorf("Out of path IDs")
} }
...@@ -33,15 +43,24 @@ func (fm *pathIDManager) getNewID() (uint32, error) { ...@@ -33,15 +43,24 @@ func (fm *pathIDManager) getNewID() (uint32, error) {
break break
} }
ret := fm.last fm.idByPath[*p.BGPPath] = fm.last
fm.ids[fm.last] = 1
fm.used++ fm.used++
return ret, nil return fm.last, nil
} }
func (fm *pathIDManager) releaseID(id uint32) { func (fm *pathIDManager) releasePath(p *route.Path) (uint32, error) {
if _, exists := fm.ids[id]; exists { if _, exists := fm.idByPath[*p.BGPPath]; !exists {
delete(fm.ids, id) return 0, fmt.Errorf("ID not found for path: %s", p.Print())
fm.used--
} }
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.
Please register or to comment