diff options
author | Naoto Hanaue <hanaue.naoto@po.ntts.co.jp> | 2015-06-30 18:13:55 +0900 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2015-07-01 21:27:31 +0900 |
commit | c9d9a6825c9fe629b069205e2a73836047a7eb3c (patch) | |
tree | 4e8814ca0b07fe7d5a0b97658aa523f2e1232cd1 | |
parent | ccfded2fee746664b576df0a068aec727cb5fae5 (diff) |
cli: support med action
-rw-r--r-- | api/gobgp.pb.go | 1 | ||||
-rw-r--r-- | api/gobgp.proto | 1 | ||||
-rw-r--r-- | gobgp/common.go | 1 | ||||
-rw-r--r-- | gobgp/policy.go | 19 | ||||
-rw-r--r-- | policy/policy.go | 6 | ||||
-rw-r--r-- | server/server.go | 3 |
6 files changed, 31 insertions, 0 deletions
diff --git a/api/gobgp.pb.go b/api/gobgp.pb.go index bc1cad51..e4214a66 100644 --- a/api/gobgp.pb.go +++ b/api/gobgp.pb.go @@ -1162,6 +1162,7 @@ func (*CommunityAction) ProtoMessage() {} type Actions struct { RouteAction string `protobuf:"bytes,1,opt,name=route_action" json:"route_action,omitempty"` Community *CommunityAction `protobuf:"bytes,2,opt,name=community" json:"community,omitempty"` + Med string `protobuf:"bytes,3,opt,name=med" json:"med,omitempty"` } func (m *Actions) Reset() { *m = Actions{} } diff --git a/api/gobgp.proto b/api/gobgp.proto index 1e789502..d52f96dc 100644 --- a/api/gobgp.proto +++ b/api/gobgp.proto @@ -431,6 +431,7 @@ message CommunityAction { message Actions { string route_action = 1; CommunityAction community = 2; + string med = 3; } message Statement { diff --git a/gobgp/common.go b/gobgp/common.go index 8eccdfaf..b58eb4aa 100644 --- a/gobgp/common.go +++ b/gobgp/common.go @@ -76,6 +76,7 @@ var conditionOpts struct { var actionOpts struct { RouteAction string `long:"route-action" description:"specifying a route action of policy (accept | reject)"` CommunityAction string `long:"community" description:"specifying a community action of policy"` + MedAction string `long:"med" description:"specifying a med action of policy"` } func formatTimedelta(d int64) string { diff --git a/gobgp/policy.go b/gobgp/policy.go index 1c76edbd..b8ea2e01 100644 --- a/gobgp/policy.go +++ b/gobgp/policy.go @@ -815,6 +815,7 @@ func showPolicyStatement(head string, pd *api.PolicyDefinition) { communityAction = fmt.Sprintf("%s[%s]", st.Actions.Community.Options, communities) } fmt.Printf("%s Community: %s\n", head, communityAction) + fmt.Printf("%s Med: %s\n", head, st.Actions.Med) fmt.Printf("%s %s\n", head, st.Actions.RouteAction) } @@ -998,6 +999,16 @@ func parseCommunityAction(communityStr string) (*api.CommunityAction, error) { return communityAction, nil } +func checkMedAction(medStr string) error { + regMed, _ := regexp.Compile("^(\\+|\\-)?([0-9]+)$") + if !regMed.MatchString(medStr) { + e := fmt.Sprintf("invalid format: %s\n", medStr) + e += "please enter the [+|-]<med>" + return fmt.Errorf("%s", e) + } + return nil +} + func parseActions() (*api.Actions, error) { actions := &api.Actions{} if actionOpts.RouteAction != "" { @@ -1015,6 +1026,13 @@ func parseActions() (*api.Actions, error) { actions.Community = community } + if actionOpts.MedAction != "" { + e := checkMedAction(actionOpts.MedAction) + if e != nil { + return nil, e + } + actions.Med = actionOpts.MedAction + } return actions, nil } @@ -1092,6 +1110,7 @@ func NewPolicyAddCmd(v string, mod func(string, []string) error) *cobra.Command policyAddCmd.Flags().StringVarP(&conditionOpts.Option, "c-option", "", "", "an option of policy condition") policyAddCmd.Flags().StringVarP(&actionOpts.RouteAction, "a-route", "", "", "a route action of policy action (accept | reject)") policyAddCmd.Flags().StringVarP(&actionOpts.CommunityAction, "a-community", "", "", "a community of policy action") + policyAddCmd.Flags().StringVarP(&actionOpts.MedAction, "a-med", "", "", "a med of policy action") } return policyAddCmd diff --git a/policy/policy.go b/policy/policy.go index 11996a4b..9ad7b349 100644 --- a/policy/policy.go +++ b/policy/policy.go @@ -1335,9 +1335,11 @@ func ActionsToApiStruct(conActions config.Actions) *api.Actions { Communities: conActions.BgpActions.SetCommunity.Communities, Options: conActions.BgpActions.SetCommunity.Options, } + medAction := fmt.Sprintf("%s", conActions.BgpActions.SetMed) resActions := &api.Actions{ RouteAction: action, Community: communityAction, + Med: medAction, } return resActions } @@ -1348,6 +1350,10 @@ func ActionsToConfigStruct(reqActions *api.Actions) config.Actions { actions.BgpActions.SetCommunity.Communities = reqActions.Community.Communities actions.BgpActions.SetCommunity.Options = reqActions.Community.Options } + if reqActions.Med != "" { + actions.BgpActions.SetMed = config.BgpSetMedType(reqActions.Med) + } + switch reqActions.RouteAction { case ROUTE_ACCEPT: actions.AcceptRoute = true diff --git a/server/server.go b/server/server.go index 437e90da..ce0edf65 100644 --- a/server/server.go +++ b/server/server.go @@ -1512,6 +1512,9 @@ func (server *BgpServer) handleGrpcAddPolicy(grpcReq *GrpcRequest) { if reqActions.Community != nil { conStatement.Actions.BgpActions.SetCommunity = statement.Actions.BgpActions.SetCommunity } + if reqActions.Med != "" { + conStatement.Actions.BgpActions.SetMed = statement.Actions.BgpActions.SetMed + } } } server.routingPolicy.PolicyDefinitionList = conPolicyList |