diff options
Diffstat (limited to 'table/policy.go')
-rw-r--r-- | table/policy.go | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/table/policy.go b/table/policy.go index 06674e1f..52506dcf 100644 --- a/table/policy.go +++ b/table/policy.go @@ -174,6 +174,7 @@ const ( ACTION_MED ACTION_AS_PATH_PREPEND ACTION_NEXTHOP + ACTION_LOCAL_PREF ) func NewMatchOption(c interface{}) (MatchOption, error) { @@ -2010,6 +2011,43 @@ func NewMedAction(c config.BgpSetMedType) (*MedAction, error) { }, nil } +type LocalPrefAction struct { + value uint32 +} + +func (a *LocalPrefAction) Type() ActionType { + return ACTION_LOCAL_PREF +} + +func (a *LocalPrefAction) Apply(path *Path) *Path { + path.setPathAttr(bgp.NewPathAttributeLocalPref(a.value)) + return path +} + +func (a *LocalPrefAction) ToApiStruct() *api.LocalPrefAction { + return &api.LocalPrefAction{ + Value: a.value, + } +} + +func NewLocalPrefActionFromApiStruct(a *api.LocalPrefAction) (*LocalPrefAction, error) { + if a == nil || a.Value == 0 { + return nil, nil + } + return &LocalPrefAction{ + value: a.Value, + }, nil +} + +func NewLocalPrefAction(value uint32) (*LocalPrefAction, error) { + if value == 0 { + return nil, nil + } + return &LocalPrefAction{ + value: value, + }, nil +} + type AsPathPrependAction struct { asn uint32 useLeftMost bool @@ -2207,6 +2245,8 @@ func (s *Statement) ToApiStruct() *api.Statement { as.Community = a.(*CommunityAction).ToApiStruct() case *MedAction: as.Med = a.(*MedAction).ToApiStruct() + case *LocalPrefAction: + as.LocalPref = a.(*LocalPrefAction).ToApiStruct() case *AsPathPrependAction: as.AsPrepend = a.(*AsPathPrependAction).ToApiStruct() case *ExtCommunityAction: @@ -2400,6 +2440,9 @@ func NewStatementFromApiStruct(a *api.Statement, dmap DefinedSetMap) (*Statement return NewMedActionFromApiStruct(a.Actions.Med) }, func() (Action, error) { + return NewLocalPrefActionFromApiStruct(a.Actions.LocalPref) + }, + func() (Action, error) { return NewAsPathPrependActionFromApiStruct(a.Actions.AsPrepend) }, func() (Action, error) { @@ -2481,6 +2524,9 @@ func NewStatement(c config.Statement, dmap DefinedSetMap) (*Statement, error) { return NewMedAction(c.Actions.BgpActions.SetMed) }, func() (Action, error) { + return NewLocalPrefAction(c.Actions.BgpActions.SetLocalPref) + }, + func() (Action, error) { return NewAsPathPrependAction(c.Actions.BgpActions.SetAsPathPrepend) }, func() (Action, error) { |