diff options
author | Wataru Ishida <ishida.wataru@lab.ntt.co.jp> | 2016-10-06 05:38:00 +0000 |
---|---|---|
committer | Wataru Ishida <ishida.wataru@lab.ntt.co.jp> | 2016-10-10 05:18:17 +0000 |
commit | d46da74d4fba3fe169d0c4f05b0e657ec95f5336 (patch) | |
tree | 94b962ebdf526bc4f84e5aef5ce18707dbfd933f /api/grpc_server.go | |
parent | 2cd0de0139cb47edac0c418f4efd4e5c6d185f63 (diff) |
policy: support large-community match/action
close #1133
Signed-off-by: Wataru Ishida <ishida.wataru@lab.ntt.co.jp>
Diffstat (limited to 'api/grpc_server.go')
-rw-r--r-- | api/grpc_server.go | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/api/grpc_server.go b/api/grpc_server.go index 61e56739..f9a2d1ba 100644 --- a/api/grpc_server.go +++ b/api/grpc_server.go @@ -905,6 +905,11 @@ func NewDefinedSetFromApiStruct(a *DefinedSet) (table.DefinedSet, error) { ExtCommunitySetName: a.Name, ExtCommunityList: a.List, }) + case table.DEFINED_TYPE_LARGE_COMMUNITY: + return table.NewLargeCommunitySet(config.LargeCommunitySet{ + LargeCommunitySetName: a.Name, + LargeCommunityList: a.List, + }) default: return nil, fmt.Errorf("invalid defined type") } @@ -960,6 +965,14 @@ func (s *Server) GetDefinedSet(ctx context.Context, arg *GetDefinedSetRequest) ( } sets = append(sets, ad) } + for _, cs := range cd.BgpDefinedSets.LargeCommunitySets { + ad := &DefinedSet{ + Type: DefinedType_LARGE_COMMUNITY, + Name: cs.LargeCommunitySetName, + List: cs.LargeCommunityList, + } + sets = append(sets, ad) + } for _, cs := range cd.BgpDefinedSets.AsPathSets { ad := &DefinedSet{ Type: DefinedType_AS_PATH, @@ -1034,6 +1047,12 @@ func toStatementApi(s *config.Statement) *Statement { Name: s.Conditions.BgpConditions.MatchExtCommunitySet.ExtCommunitySet, } } + if s.Conditions.BgpConditions.MatchLargeCommunitySet.LargeCommunitySet != "" { + cs.CommunitySet = &MatchSet{ + Type: MatchType(s.Conditions.BgpConditions.MatchLargeCommunitySet.MatchSetOptions.ToInt()), + Name: s.Conditions.BgpConditions.MatchLargeCommunitySet.LargeCommunitySet, + } + } if s.Conditions.BgpConditions.RouteType != "" { cs.RouteType = Conditions_RouteType(s.Conditions.BgpConditions.RouteType.ToInt()) } @@ -1096,6 +1115,15 @@ func toStatementApi(s *config.Statement) *Statement { Communities: s.Actions.BgpActions.SetExtCommunity.SetExtCommunityMethod.CommunitiesList, } }(), + LargeCommunity: func() *CommunityAction { + if len(s.Actions.BgpActions.SetLargeCommunity.SetLargeCommunityMethod.CommunitiesList) == 0 { + return nil + } + return &CommunityAction{ + Type: CommunityActionType(config.BgpSetCommunityOptionTypeToIntMap[config.BgpSetCommunityOptionType(s.Actions.BgpActions.SetLargeCommunity.Options)]), + Communities: s.Actions.BgpActions.SetLargeCommunity.SetLargeCommunityMethod.CommunitiesList, + } + }(), Nexthop: func() *NexthopAction { if len(string(s.Actions.BgpActions.SetNextHop)) == 0 { return nil @@ -1255,6 +1283,21 @@ func NewExtCommunityConditionFromApiStruct(a *MatchSet) (*table.ExtCommunityCond return table.NewExtCommunityCondition(c) } +func NewLargeCommunityConditionFromApiStruct(a *MatchSet) (*table.LargeCommunityCondition, error) { + if a == nil { + return nil, nil + } + typ, err := toConfigMatchSetOption(a.Type) + if err != nil { + return nil, err + } + c := config.MatchLargeCommunitySet{ + LargeCommunitySet: a.Name, + MatchSetOptions: typ, + } + return table.NewLargeCommunityCondition(c) +} + func NewRoutingActionFromApiStruct(a RouteAction) (*table.RoutingAction, error) { if a == RouteAction_NONE { return nil, nil @@ -1292,6 +1335,18 @@ func NewExtCommunityActionFromApiStruct(a *CommunityAction) (*table.ExtCommunity }) } +func NewLargeCommunityActionFromApiStruct(a *CommunityAction) (*table.LargeCommunityAction, error) { + if a == nil { + return nil, nil + } + return table.NewLargeCommunityAction(config.SetLargeCommunity{ + Options: config.IntToBgpSetCommunityOptionTypeMap[int(a.Type)], + SetLargeCommunityMethod: config.SetLargeCommunityMethod{ + CommunitiesList: a.Communities, + }, + }) +} + func NewMedActionFromApiStruct(a *MedAction) (*table.MedAction, error) { if a == nil { return nil, nil @@ -1369,6 +1424,9 @@ func NewStatementFromApiStruct(a *Statement) (*table.Statement, error) { func() (table.Condition, error) { return NewExtCommunityConditionFromApiStruct(a.Conditions.ExtCommunitySet) }, + func() (table.Condition, error) { + return NewLargeCommunityConditionFromApiStruct(a.Conditions.LargeCommunitySet) + }, } cs = make([]table.Condition, 0, len(cfs)) for _, f := range cfs { @@ -1394,6 +1452,9 @@ func NewStatementFromApiStruct(a *Statement) (*table.Statement, error) { return NewExtCommunityActionFromApiStruct(a.Actions.ExtCommunity) }, func() (table.Action, error) { + return NewLargeCommunityActionFromApiStruct(a.Actions.LargeCommunity) + }, + func() (table.Action, error) { return NewMedActionFromApiStruct(a.Actions.Med) }, func() (table.Action, error) { |