summaryrefslogtreecommitdiffhomepage
path: root/table/table.go
diff options
context:
space:
mode:
authorISHIDA Wataru <ishida.wataru@lab.ntt.co.jp>2015-11-29 04:08:36 +0900
committerFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2015-12-08 14:45:37 +0900
commita719a3de6e8b2bb7803e02e7e05ea8e854d6f396 (patch)
treefbe41ae4055542414a7a02d81c87a0fc57b65f5c /table/table.go
parent3213eed6a5aca1625ffa03ab410ffc587121b9da (diff)
server/table: use only one rib for multiple route server clients
speed up and reduce memory footprint Signed-off-by: ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp>
Diffstat (limited to 'table/table.go')
-rw-r--r--table/table.go45
1 files changed, 32 insertions, 13 deletions
diff --git a/table/table.go b/table/table.go
index cf14d5c1..36a29ed4 100644
--- a/table/table.go
+++ b/table/table.go
@@ -51,28 +51,28 @@ func (t *Table) insert(path *Path) *Destination {
}
func (t *Table) DeleteDestByPeer(peerInfo *PeerInfo) []*Destination {
- changedDests := make([]*Destination, 0)
- for _, dest := range t.destinations {
- newKnownPathList := make([]*Path, 0)
- for _, p := range dest.GetKnownPathList() {
- if !p.GetSource().Equal(peerInfo) {
- newKnownPathList = append(newKnownPathList, p)
+ dsts := []*Destination{}
+ for _, dst := range t.destinations {
+ match := false
+ for _, p := range dst.knownPathList {
+ if p.GetSource().Equal(peerInfo) {
+ dst.addWithdraw(p)
+ match = true
}
}
- if len(newKnownPathList) != len(dest.GetKnownPathList()) {
- changedDests = append(changedDests, dest)
- dest.setKnownPathList(newKnownPathList)
+ if match {
+ dsts = append(dsts, dst)
}
}
- return changedDests
+ return dsts
}
func (t *Table) deletePathsByVrf(vrf *Vrf) []*Path {
pathList := make([]*Path, 0)
for _, dest := range t.destinations {
- for _, p := range dest.GetKnownPathList() {
+ for _, p := range dest.knownPathList {
var rd bgp.RouteDistinguisherInterface
- nlri := p.GetNlri()
+ nlri := p.nlri
switch nlri.(type) {
case *bgp.LabeledVPNIPAddrPrefix:
rd = nlri.(*bgp.LabeledVPNIPAddrPrefix).RD
@@ -104,7 +104,7 @@ func (t *Table) deleteRTCPathsByVrf(vrf *Vrf, vrfs map[string]*Vrf) []*Path {
nlri := dest.GetNlri().(*bgp.RouteTargetMembershipNLRI)
rhs := nlri.RouteTarget.String()
if lhs == rhs && isLastTargetUser(vrfs, target) {
- for _, p := range dest.GetKnownPathList() {
+ for _, p := range dest.knownPathList {
if p.IsLocal() {
p.IsWithdraw = true
pathList = append(pathList, p)
@@ -210,3 +210,22 @@ func (t *Table) setDestination(key string, dest *Destination) {
func (t *Table) tableKey(nlri bgp.AddrPrefixInterface) string {
return nlri.String()
}
+
+func (t *Table) Bests(id string) []*Path {
+ paths := make([]*Path, 0, len(t.destinations))
+ for _, dst := range t.destinations {
+ path := dst.GetBestPath(id)
+ if path != nil {
+ paths = append(paths, path)
+ }
+ }
+ return paths
+}
+
+func (t *Table) GetKnownPathList(id string) []*Path {
+ paths := make([]*Path, 0, len(t.destinations))
+ for _, dst := range t.destinations {
+ paths = append(paths, dst.GetKnownPathList(id)...)
+ }
+ return paths
+}