diff options
author | ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp> | 2016-05-31 04:46:20 +0000 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2016-06-06 12:43:20 +0900 |
commit | 222d4dba8e2c97f0edc2b1e97c0afa1d25f44822 (patch) | |
tree | 1215cac150845010040f3722e9a6fb886f794d89 | |
parent | b63e1c1fc3c40b58ba798bbae4e122f0eedaf55d (diff) |
table: return default value(100) when local-pref attr doesn't exist
Signed-off-by: ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp>
-rw-r--r-- | table/destination.go | 12 | ||||
-rw-r--r-- | table/path.go | 15 |
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 |