summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--table/destination.go12
-rw-r--r--table/path.go15
2 files changed, 16 insertions, 11 deletions
diff --git a/table/destination.go b/table/destination.go
index f695f6be..8b80f29b 100644
--- a/table/destination.go
+++ b/table/destination.go
@@ -557,16 +557,8 @@ func compareByLocalPref(path1, path2 *Path) *Path {
//
// # Default local-pref values is 100
log.Debugf("enter compareByLocalPref")
- attribute1 := path1.getPathAttr(bgp.BGP_ATTR_TYPE_LOCAL_PREF)
- attribute2 := path2.getPathAttr(bgp.BGP_ATTR_TYPE_LOCAL_PREF)
-
- if attribute1 == nil || attribute2 == nil {
- return nil
- }
-
- localPref1 := attribute1.(*bgp.PathAttributeLocalPref).Value
- localPref2 := attribute2.(*bgp.PathAttributeLocalPref).Value
-
+ localPref1, _ := path1.GetLocalPref()
+ localPref2, _ := path2.GetLocalPref()
// Highest local-preference value is preferred.
if localPref1 > localPref2 {
return path1
diff --git a/table/path.go b/table/path.go
index 77b811d1..4a0d9031 100644
--- a/table/path.go
+++ b/table/path.go
@@ -28,6 +28,10 @@ import (
"time"
)
+const (
+ DEFAULT_LOCAL_PREF = 100
+)
+
type Bitmap []uint64
func (b Bitmap) Flag(i uint) {
@@ -200,7 +204,7 @@ func (path *Path) UpdatePathAttrs(global *config.Global, peer *config.Neighbor)
// for connected or local prefixes.
// We set default local-pref 100.
if pref := path.getPathAttr(bgp.BGP_ATTR_TYPE_LOCAL_PREF); pref == nil || !path.IsLocal() {
- path.setPathAttr(bgp.NewPathAttributeLocalPref(100))
+ path.setPathAttr(bgp.NewPathAttributeLocalPref(DEFAULT_LOCAL_PREF))
}
// RFC4456: BGP Route Reflection
@@ -834,6 +838,15 @@ func (path *Path) GetOrigin() (uint8, error) {
return 0, fmt.Errorf("no origin path attr")
}
+func (path *Path) GetLocalPref() (uint32, error) {
+ lp := uint32(DEFAULT_LOCAL_PREF)
+ attr := path.getPathAttr(bgp.BGP_ATTR_TYPE_LOCAL_PREF)
+ if attr != nil {
+ lp = attr.(*bgp.PathAttributeLocalPref).Value
+ }
+ return lp, nil
+}
+
func (lhs *Path) Equal(rhs *Path) bool {
if rhs == nil {
return false