summaryrefslogtreecommitdiffhomepage
path: root/cmd
diff options
context:
space:
mode:
authorFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2018-08-18 22:02:06 +0900
committerFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2018-08-23 10:05:19 +0900
commit008c961ecd943739c5db63fcd931904804a45aa5 (patch)
treea56ebdc908ce1b387c030cf6223e7f5f5d76d5c8 /cmd
parent7e07240b292946c5fdd281fcc06d0cb8438c349a (diff)
policy cleanup
- remove ReplaceDefinedSet and ReplaceStatement APIs; not intutive and should create a new one instead of modifying the existing. - Rename ReplacePolicyAssignment to SetPolicyAssignment API; we use internally SetPolicy() name from the beginning. - Rename UpdatePolicy() to SetPolicies() API; It doesn't update anything so the name is confusing. It discards the all policies and create policies from the argument. - Changes some member names in structures for policy. Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
Diffstat (limited to 'cmd')
-rw-r--r--cmd/gobgp/cmd/neighbor.go18
-rw-r--r--cmd/gobgp/cmd/policy.go32
-rw-r--r--cmd/gobgpd/main.go16
3 files changed, 22 insertions, 44 deletions
diff --git a/cmd/gobgp/cmd/neighbor.go b/cmd/gobgp/cmd/neighbor.go
index e863003a..a3c16c9c 100644
--- a/cmd/gobgp/cmd/neighbor.go
+++ b/cmd/gobgp/cmd/neighbor.go
@@ -1040,7 +1040,7 @@ func showNeighborPolicy(remoteIP, policyType string, indent int) error {
}
fmt.Printf("%s policy:\n", strings.Title(policyType))
- fmt.Printf("%sDefault: %s\n", strings.Repeat(" ", indent), assignment.Default.String())
+ fmt.Printf("%sDefault: %s\n", strings.Repeat(" ", indent), assignment.DefaultAction.String())
for _, p := range assignment.Policies {
fmt.Printf("%sName %s:\n", strings.Repeat(" ", indent), p.Name)
printPolicy(indent+4, p)
@@ -1069,23 +1069,19 @@ func extractDefaultAction(args []string) ([]string, api.RouteAction, error) {
}
func modNeighborPolicy(remoteIP, policyType, cmdType string, args []string) error {
- resource := api.Resource_GLOBAL
- if remoteIP != "" {
- resource = api.Resource_LOCAL
- } else {
+ if remoteIP == "" {
remoteIP = GLOBAL_RIB_NAME
}
assign := &api.PolicyAssignment{
- Name: remoteIP,
- Resource: resource,
+ Name: remoteIP,
}
switch strings.ToLower(policyType) {
case "import":
- assign.Type = api.PolicyDirection_IMPORT
+ assign.Direction = api.PolicyDirection_IMPORT
case "export":
- assign.Type = api.PolicyDirection_EXPORT
+ assign.Direction = api.PolicyDirection_EXPORT
}
usage := fmt.Sprintf("usage: gobgp neighbor %s policy %s %s", remoteIP, policyType, cmdType)
@@ -1105,7 +1101,7 @@ func modNeighborPolicy(remoteIP, policyType, cmdType string, args []string) erro
if err != nil {
return fmt.Errorf("%s\n%s <policy name>... [default {%s|%s}]", err, usage, "accept", "reject")
}
- assign.Default = def
+ assign.DefaultAction = def
}
ps := make([]*api.Policy, 0, len(args))
for _, name := range args {
@@ -1118,7 +1114,7 @@ func modNeighborPolicy(remoteIP, policyType, cmdType string, args []string) erro
Assignment: assign,
})
case CMD_SET:
- _, err = client.ReplacePolicyAssignment(ctx, &api.ReplacePolicyAssignmentRequest{
+ _, err = client.SetPolicyAssignment(ctx, &api.SetPolicyAssignmentRequest{
Assignment: assign,
})
case CMD_DEL:
diff --git a/cmd/gobgp/cmd/policy.go b/cmd/gobgp/cmd/policy.go
index df9c5c8f..f94cf17e 100644
--- a/cmd/gobgp/cmd/policy.go
+++ b/cmd/gobgp/cmd/policy.go
@@ -232,7 +232,7 @@ func showDefinedSet(v string, args []string) error {
} else if err != nil {
return err
}
- m = append(m, r.Set)
+ m = append(m, r.DefinedSet)
}
if globalOpts.Json {
@@ -443,7 +443,7 @@ func modDefinedSet(settype string, modtype string, args []string) error {
switch modtype {
case CMD_ADD:
_, err = client.AddDefinedSet(ctx, &api.AddDefinedSetRequest{
- Set: d,
+ DefinedSet: d,
})
case CMD_DEL:
all := false
@@ -451,12 +451,8 @@ func modDefinedSet(settype string, modtype string, args []string) error {
all = true
}
_, err = client.DeleteDefinedSet(ctx, &api.DeleteDefinedSetRequest{
- Set: d,
- All: all,
- })
- case CMD_SET:
- _, err = client.ReplaceDefinedSet(ctx, &api.ReplaceDefinedSetRequest{
- Set: d,
+ DefinedSet: d,
+ All: all,
})
}
return err
@@ -853,10 +849,6 @@ func modCondition(name, op string, args []string) error {
_, err = client.DeleteStatement(ctx, &api.DeleteStatementRequest{
Statement: stmt,
})
- case CMD_SET:
- _, err = client.ReplaceStatement(ctx, &api.ReplaceStatementRequest{
- Statement: stmt,
- })
default:
return fmt.Errorf("invalid operation: %s", op)
}
@@ -987,10 +979,6 @@ func modAction(name, op string, args []string) error {
_, err = client.DeleteStatement(ctx, &api.DeleteStatementRequest{
Statement: stmt,
})
- case CMD_SET:
- _, err = client.ReplaceStatement(ctx, &api.ReplaceStatementRequest{
- Statement: stmt,
- })
default:
return fmt.Errorf("invalid operation: %s", op)
}
@@ -1029,12 +1017,6 @@ func modPolicy(modtype string, args []string) error {
All: all,
PreserveStatements: true,
})
- case CMD_SET:
- _, err = client.ReplacePolicy(ctx, &api.ReplacePolicyRequest{
- Policy: policy,
- PreserveStatements: true,
- ReferExistingStatements: true,
- })
}
return err
}
@@ -1059,7 +1041,7 @@ func NewPolicyCmd() *cobra.Command {
}
},
}
- for _, w := range []string{CMD_ADD, CMD_DEL, CMD_SET} {
+ for _, w := range []string{CMD_ADD, CMD_DEL} {
subcmd := &cobra.Command{
Use: w,
Run: func(c *cobra.Command, args []string) {
@@ -1074,7 +1056,7 @@ func NewPolicyCmd() *cobra.Command {
}
stmtCmdImpl := &cobra.Command{}
- for _, v := range []string{CMD_ADD, CMD_DEL, CMD_SET} {
+ for _, v := range []string{CMD_ADD, CMD_DEL} {
cmd := &cobra.Command{
Use: v,
}
@@ -1130,7 +1112,7 @@ func NewPolicyCmd() *cobra.Command {
}
policyCmd.AddCommand(stmtCmd)
- for _, v := range []string{CMD_ADD, CMD_DEL, CMD_SET} {
+ for _, v := range []string{CMD_ADD, CMD_DEL} {
cmd := &cobra.Command{
Use: v,
Run: func(c *cobra.Command, args []string) {
diff --git a/cmd/gobgpd/main.go b/cmd/gobgpd/main.go
index 463387b9..c212562c 100644
--- a/cmd/gobgpd/main.go
+++ b/cmd/gobgpd/main.go
@@ -273,9 +273,9 @@ func main() {
if err != nil {
log.Warn(err)
} else {
- apiServer.UpdatePolicy(context.Background(), &api.UpdatePolicyRequest{
- Sets: rp.DefinedSet,
- Policies: rp.PolicyDefinition,
+ apiServer.SetPolicies(context.Background(), &api.SetPoliciesRequest{
+ DefinedSets: rp.DefinedSets,
+ Policies: rp.Policies,
})
}
@@ -301,9 +301,9 @@ func main() {
if err != nil {
log.Warn(err)
} else {
- apiServer.UpdatePolicy(context.Background(), &api.UpdatePolicyRequest{
- Sets: rp.DefinedSet,
- Policies: rp.PolicyDefinition,
+ apiServer.SetPolicies(context.Background(), &api.SetPoliciesRequest{
+ DefinedSets: rp.DefinedSets,
+ Policies: rp.Policies,
})
}
}
@@ -332,7 +332,7 @@ func main() {
def := toDefaultTable(a.DefaultImportPolicy)
ps := toPolicies(a.ImportPolicyList)
- apiServer.ReplacePolicyAssignment(context.Background(), &api.ReplacePolicyAssignmentRequest{
+ apiServer.SetPolicyAssignment(context.Background(), &api.SetPolicyAssignmentRequest{
Assignment: server.NewAPIPolicyAssignmentFromTableStruct(&table.PolicyAssignment{
Name: table.GLOBAL_RIB_NAME,
Type: table.POLICY_DIRECTION_IMPORT,
@@ -343,7 +343,7 @@ func main() {
def = toDefaultTable(a.DefaultExportPolicy)
ps = toPolicies(a.ExportPolicyList)
- apiServer.ReplacePolicyAssignment(context.Background(), &api.ReplacePolicyAssignmentRequest{
+ apiServer.SetPolicyAssignment(context.Background(), &api.SetPolicyAssignmentRequest{
Assignment: server.NewAPIPolicyAssignmentFromTableStruct(&table.PolicyAssignment{
Name: table.GLOBAL_RIB_NAME,
Type: table.POLICY_DIRECTION_EXPORT,