diff options
author | Naoto Hanaue <hanaue.naoto@po.ntts.co.jp> | 2015-06-23 17:13:45 +0900 |
---|---|---|
committer | Naoto Hanaue <hanaue.naoto@po.ntts.co.jp> | 2015-06-26 13:37:52 +0900 |
commit | b3bd568b8dd4a5536428a1bc9a3612b0f1315a39 (patch) | |
tree | dbca40cf4a409d189a60e6c6ad8944ae5aa07b50 /table/path.go | |
parent | 69b36e90ba70131bf67127968e6bb8fa80460161 (diff) |
policy: support med action
Diffstat (limited to 'table/path.go')
-rw-r--r-- | table/path.go | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/table/path.go b/table/path.go index c095ab24..a82c5e59 100644 --- a/table/path.go +++ b/table/path.go @@ -25,6 +25,7 @@ import ( "net" "reflect" "time" + "math" ) type Path interface { @@ -40,6 +41,7 @@ type Path interface { SetCommunities([]uint32, bool) RemoveCommunities([]uint32) int ClearCommunities() + SetMed(uint32, bool, bool) error setSource(source *PeerInfo) GetSource() *PeerInfo GetSourceAs() uint32 @@ -479,6 +481,41 @@ func (pd *PathDefault) ClearCommunities() { } } +// SetMed replace, add or subtraction med with new ones. +func (pd *PathDefault) SetMed(med uint32, doReplace bool, doSubstruction bool) error { + newMed := &bgp.PathAttributeMultiExitDisc{} + idx, attr := pd.getPathAttr(bgp.BGP_ATTR_TYPE_MULTI_EXIT_DISC) + if attr != nil{ + m := attr.(*bgp.PathAttributeMultiExitDisc) + if doReplace { + newMed = bgp.NewPathAttributeMultiExitDisc(med) + } else { + if doSubstruction { + if m.Value - med < 0 { + return fmt.Errorf("med value invalid. the underflow threshold") + } + newMed = bgp.NewPathAttributeMultiExitDisc(m.Value - med) + } else { + if m.Value + med > math.MaxUint32 { + return fmt.Errorf("med value invalid. the overflow threshold") + } + newMed = bgp.NewPathAttributeMultiExitDisc(m.Value + med) + } + } + pd.pathAttrs[idx] = newMed + } else { + if doReplace { + newMed = bgp.NewPathAttributeMultiExitDisc(med) + } else { + if !doSubstruction { + newMed = bgp.NewPathAttributeMultiExitDisc(med) + } + } + pd.pathAttrs[idx] = newMed + } + return nil +} + // create Path object based on route family func CreatePath(source *PeerInfo, nlri bgp.AddrPrefixInterface, attrs []bgp.PathAttributeInterface, isWithdraw bool, now time.Time) (Path, error) { |