diff options
Diffstat (limited to 'table')
-rw-r--r-- | table/path.go | 9 | ||||
-rw-r--r-- | table/table_manager.go | 14 |
2 files changed, 23 insertions, 0 deletions
diff --git a/table/path.go b/table/path.go index 875fd04e..cf4603f2 100644 --- a/table/path.go +++ b/table/path.go @@ -154,6 +154,7 @@ type Path struct { info *originInfo IsWithdraw bool pathAttrs []bgp.PathAttributeInterface + attrsHash uint32 reason BestPathReason parent *Path dels []bgp.BGPAttrType @@ -1242,3 +1243,11 @@ func (p *Path) ToLocal() *Path { path.IsNexthopInvalid = p.IsNexthopInvalid return path } + +func (p *Path) SetHash(v uint32) { + p.attrsHash = v +} + +func (p *Path) GetHash() uint32 { + return p.attrsHash +} diff --git a/table/table_manager.go b/table/table_manager.go index 0331cc70..b94b546e 100644 --- a/table/table_manager.go +++ b/table/table_manager.go @@ -21,6 +21,7 @@ import ( "net" "time" + farm "github.com/dgryski/go-farm" "github.com/osrg/gobgp/packet/bgp" log "github.com/sirupsen/logrus" ) @@ -68,9 +69,21 @@ func ProcessMessage(m *bgp.BGPMessage, peerInfo *PeerInfo, timestamp time.Time) if reach != nil { listLen += len(reach.Value) } + + var hash uint32 + if len(adds) > 0 || reach != nil { + total := bytes.NewBuffer(make([]byte, 0)) + for _, a := range attrs { + b, _ := a.Serialize() + total.Write(b) + } + hash = farm.Hash32(total.Bytes()) + } + pathList := make([]*Path, 0, listLen) for _, nlri := range adds { p := NewPath(peerInfo, nlri, false, attrs, timestamp, false) + p.SetHash(hash) pathList = append(pathList, p) } if reach != nil { @@ -81,6 +94,7 @@ func ProcessMessage(m *bgp.BGPMessage, peerInfo *PeerInfo, timestamp time.Time) for _, nlri := range reach.Value { p := NewPath(peerInfo, nlri, false, reachAttrs, timestamp, false) + p.SetHash(hash) pathList = append(pathList, p) } } |