diff options
author | ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp> | 2015-06-23 11:13:40 +0900 |
---|---|---|
committer | ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp> | 2015-06-23 11:13:40 +0900 |
commit | 4867124319c179d2a573d465a5dff2845176fb99 (patch) | |
tree | 395c5f3b782156112c900752a5b6b4c5b964be5b /table | |
parent | 706ccc9d71b3bd7b0555bf657dc80268b79222df (diff) |
table: add Equal() method to compare PeerInfo
this patch fixes the wrong behavior shown below
$ gobgp global rib add 10.0.0.0/24
$ gobgp global rib del 10.0.0.0/24
$ gobgp global rib
Network Next Hop AS_PATH Age Attrs
*> 10.0.0.0/24 0.0.0.0 65000 00:05:48 [{Origin: IGP}]
since we used to compare path's source by PeerInfo's pointer, locally
originated routes is considered as a different route even if they have
same prefix.
this patch introduce Equal() method to compare PeerInfo's content and
fix this wrong behavior.
Signed-off-by: ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp>
Diffstat (limited to 'table')
-rw-r--r-- | table/destination.go | 35 | ||||
-rw-r--r-- | table/message.go | 2 | ||||
-rw-r--r-- | table/path.go | 9 | ||||
-rw-r--r-- | table/table.go | 2 |
4 files changed, 36 insertions, 12 deletions
diff --git a/table/destination.go b/table/destination.go index a58ffbf1..5805209f 100644 --- a/table/destination.go +++ b/table/destination.go @@ -48,6 +48,21 @@ type PeerInfo struct { Address net.IP } +func (lhs *PeerInfo) Equal(rhs *PeerInfo) bool { + if lhs == rhs { + return true + } + + if rhs == nil { + return false + } + + if (lhs.AS == rhs.AS) && lhs.ID.Equal(rhs.ID) && lhs.LocalID.Equal(rhs.LocalID) && lhs.Address.Equal(rhs.Address) { + return true + } + return false +} + type Destination interface { Calculate(localAsn uint32) (Path, string, error) getRouteFamily() bgp.RouteFamily @@ -183,7 +198,7 @@ func (dd *DestinationDefault) removeOldPathsFromSource(source *PeerInfo) []Path tempKnownPathList := make([]Path, 0) for _, path := range dd.knownPathList { - if path.GetSource() == source { + if path.GetSource().Equal(source) { removePaths = append(removePaths, path) } else { tempKnownPathList = append(tempKnownPathList, path) @@ -302,7 +317,7 @@ func (dest *DestinationDefault) removeWithdrawals() { for _, path := range dest.knownPathList { // We have a match if the source are same. // TODO add GetSource to Path interface - if path.GetSource() == withdraw.GetSource() { + if path.GetSource().Equal(withdraw.GetSource()) { isFound = true matches[path.String()] = path wMatches[withdraw.String()] = withdraw @@ -401,7 +416,7 @@ func (dest *DestinationDefault) removeOldPaths() { // version num. as newPaths are implicit withdrawal of old // paths and when doing RouteRefresh (not EnhancedRouteRefresh) // we get same paths again. - if newPath.GetSource() == path.GetSource() { + if newPath.GetSource().Equal(path.GetSource()) { oldPaths = append(oldPaths, path) break } @@ -590,14 +605,14 @@ func compareByLocalPref(path1, path2 Path) Path { func compareByLocalOrigin(path1, path2 Path) Path { - // """Select locally originating path as best path. - // Locally originating routes are network routes, redistributed routes, - // or aggregated routes. - // Returns None if given paths have same source. - // """ - // # If both paths are from same sources we cannot compare them here. + // Select locally originating path as best path. + // Locally originating routes are network routes, redistributed routes, + // or aggregated routes. + // Returns None if given paths have same source. + // + // If both paths are from same sources we cannot compare them here. log.Debugf("enter compareByLocalOrigin") - if path1.GetSource() == path2.GetSource() { + if path1.GetSource().Equal(path2.GetSource()) { return nil } diff --git a/table/message.go b/table/message.go index 5b444ce0..4455e06b 100644 --- a/table/message.go +++ b/table/message.go @@ -215,7 +215,7 @@ func isMergeable(p1 Path, p2 Path) bool { if p1.GetRouteFamily() != bgp.RF_IPv4_UC { return false } - if p1.GetSource() == p2.GetSource() && isSamePathAttrs(p1.getPathAttrs(), p2.getPathAttrs()) { + if p1.GetSource().Equal(p2.GetSource()) && isSamePathAttrs(p1.getPathAttrs(), p2.getPathAttrs()) { return true } return false diff --git a/table/path.go b/table/path.go index 05a54aaa..c095ab24 100644 --- a/table/path.go +++ b/table/path.go @@ -54,6 +54,7 @@ type Path interface { Clone(IsWithdraw bool) Path getTimestamp() time.Time setTimestamp(t time.Time) + isLocal() bool ToApiStruct() *api.Path MarshalJSON() ([]byte, error) } @@ -180,6 +181,14 @@ func (pd *PathDefault) setTimestamp(t time.Time) { pd.timestamp = t } +func (pd *PathDefault) isLocal() bool { + var ret bool + if pd.source.Address == nil { + ret = true + } + return ret +} + func (pd *PathDefault) ToApiStruct() *api.Path { pathAttrs := func(arg []bgp.PathAttributeInterface) []*api.PathAttr { ret := make([]*api.PathAttr, 0, len(arg)) diff --git a/table/table.go b/table/table.go index 22499f5a..7fa6b17a 100644 --- a/table/table.go +++ b/table/table.go @@ -98,7 +98,7 @@ func (td *TableDefault) DeleteDestByPeer(peerInfo *PeerInfo) []Destination { for _, dest := range td.destinations { newKnownPathList := make([]Path, 0) for _, p := range dest.getKnownPathList() { - if p.GetSource() != peerInfo { + if !p.GetSource().Equal(peerInfo) { newKnownPathList = append(newKnownPathList, p) } } |