summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--api/gobgp.pb.go59
-rw-r--r--api/gobgp.proto17
-rw-r--r--gobgp/cmd/global.go19
-rw-r--r--gobgp/cmd/neighbor.go121
-rw-r--r--server/grpc_server.go52
-rw-r--r--server/server.go164
6 files changed, 205 insertions, 227 deletions
diff --git a/api/gobgp.pb.go b/api/gobgp.pb.go
index 07e42a19..80a4d789 100644
--- a/api/gobgp.pb.go
+++ b/api/gobgp.pb.go
@@ -151,6 +151,29 @@ func (x RouteAction) String() string {
return proto.EnumName(RouteAction_name, int32(x))
}
+type PolicyType int32
+
+const (
+ PolicyType_IN PolicyType = 0
+ PolicyType_IMPORT PolicyType = 1
+ PolicyType_EXPORT PolicyType = 2
+)
+
+var PolicyType_name = map[int32]string{
+ 0: "IN",
+ 1: "IMPORT",
+ 2: "EXPORT",
+}
+var PolicyType_value = map[string]int32{
+ "IN": 0,
+ "IMPORT": 1,
+ "EXPORT": 2,
+}
+
+func (x PolicyType) String() string {
+ return proto.EnumName(PolicyType_name, int32(x))
+}
+
type Error_ErrorCode int32
const (
@@ -603,35 +626,18 @@ func (m *PolicyDefinition) GetStatementList() []*Statement {
}
type ApplyPolicy struct {
- ImportPolicies []*PolicyDefinition `protobuf:"bytes,1,rep,name=import_policies" json:"import_policies,omitempty"`
- DefaultImportPolicy RouteAction `protobuf:"varint,2,opt,name=default_import_policy,enum=gobgpapi.RouteAction" json:"default_import_policy,omitempty"`
- ExportPolicies []*PolicyDefinition `protobuf:"bytes,3,rep,name=export_policies" json:"export_policies,omitempty"`
- DefaultExportPolicy RouteAction `protobuf:"varint,4,opt,name=default_export_policy,enum=gobgpapi.RouteAction" json:"default_export_policy,omitempty"`
- InPolicies []*PolicyDefinition `protobuf:"bytes,5,rep,name=in_policies" json:"in_policies,omitempty"`
- DefaultInPolicy RouteAction `protobuf:"varint,6,opt,name=default_in_policy,enum=gobgpapi.RouteAction" json:"default_in_policy,omitempty"`
+ Type PolicyType `protobuf:"varint,1,opt,name=type,enum=gobgpapi.PolicyType" json:"type,omitempty"`
+ Policies []*PolicyDefinition `protobuf:"bytes,2,rep,name=policies" json:"policies,omitempty"`
+ Default RouteAction `protobuf:"varint,3,opt,name=default,enum=gobgpapi.RouteAction" json:"default,omitempty"`
}
func (m *ApplyPolicy) Reset() { *m = ApplyPolicy{} }
func (m *ApplyPolicy) String() string { return proto.CompactTextString(m) }
func (*ApplyPolicy) ProtoMessage() {}
-func (m *ApplyPolicy) GetImportPolicies() []*PolicyDefinition {
+func (m *ApplyPolicy) GetPolicies() []*PolicyDefinition {
if m != nil {
- return m.ImportPolicies
- }
- return nil
-}
-
-func (m *ApplyPolicy) GetExportPolicies() []*PolicyDefinition {
- if m != nil {
- return m.ExportPolicies
- }
- return nil
-}
-
-func (m *ApplyPolicy) GetInPolicies() []*PolicyDefinition {
- if m != nil {
- return m.InPolicies
+ return m.Policies
}
return nil
}
@@ -712,6 +718,7 @@ func init() {
proto.RegisterEnum("gobgpapi.Resource", Resource_name, Resource_value)
proto.RegisterEnum("gobgpapi.Operation", Operation_name, Operation_value)
proto.RegisterEnum("gobgpapi.RouteAction", RouteAction_name, RouteAction_value)
+ proto.RegisterEnum("gobgpapi.PolicyType", PolicyType_name, PolicyType_value)
proto.RegisterEnum("gobgpapi.Error_ErrorCode", Error_ErrorCode_name, Error_ErrorCode_value)
}
@@ -733,7 +740,7 @@ type GobgpApiClient interface {
Enable(ctx context.Context, in *Arguments, opts ...grpc.CallOption) (*Error, error)
Disable(ctx context.Context, in *Arguments, opts ...grpc.CallOption) (*Error, error)
ModPath(ctx context.Context, opts ...grpc.CallOption) (GobgpApi_ModPathClient, error)
- GetNeighborPolicy(ctx context.Context, in *Arguments, opts ...grpc.CallOption) (*ApplyPolicy, error)
+ GetNeighborPolicy(ctx context.Context, in *PolicyArguments, opts ...grpc.CallOption) (*ApplyPolicy, error)
ModNeighborPolicy(ctx context.Context, opts ...grpc.CallOption) (GobgpApi_ModNeighborPolicyClient, error)
GetPolicyRoutePolicies(ctx context.Context, in *PolicyArguments, opts ...grpc.CallOption) (GobgpApi_GetPolicyRoutePoliciesClient, error)
GetPolicyRoutePolicy(ctx context.Context, in *PolicyArguments, opts ...grpc.CallOption) (*PolicyDefinition, error)
@@ -925,7 +932,7 @@ func (x *gobgpApiModPathClient) CloseAndRecv() (*Error, error) {
return m, nil
}
-func (c *gobgpApiClient) GetNeighborPolicy(ctx context.Context, in *Arguments, opts ...grpc.CallOption) (*ApplyPolicy, error) {
+func (c *gobgpApiClient) GetNeighborPolicy(ctx context.Context, in *PolicyArguments, opts ...grpc.CallOption) (*ApplyPolicy, error) {
out := new(ApplyPolicy)
err := grpc.Invoke(ctx, "/gobgpapi.GobgpApi/GetNeighborPolicy", in, out, c.cc, opts...)
if err != nil {
@@ -1252,7 +1259,7 @@ type GobgpApiServer interface {
Enable(context.Context, *Arguments) (*Error, error)
Disable(context.Context, *Arguments) (*Error, error)
ModPath(GobgpApi_ModPathServer) error
- GetNeighborPolicy(context.Context, *Arguments) (*ApplyPolicy, error)
+ GetNeighborPolicy(context.Context, *PolicyArguments) (*ApplyPolicy, error)
ModNeighborPolicy(GobgpApi_ModNeighborPolicyServer) error
GetPolicyRoutePolicies(*PolicyArguments, GobgpApi_GetPolicyRoutePoliciesServer) error
GetPolicyRoutePolicy(context.Context, *PolicyArguments) (*PolicyDefinition, error)
@@ -1435,7 +1442,7 @@ func (x *gobgpApiModPathServer) Recv() (*ModPathArguments, error) {
}
func _GobgpApi_GetNeighborPolicy_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error) (interface{}, error) {
- in := new(Arguments)
+ in := new(PolicyArguments)
if err := dec(in); err != nil {
return nil, err
}
diff --git a/api/gobgp.proto b/api/gobgp.proto
index cc58a3d9..f575d139 100644
--- a/api/gobgp.proto
+++ b/api/gobgp.proto
@@ -31,7 +31,7 @@ service GobgpApi {
rpc Enable(Arguments) returns (Error) {}
rpc Disable(Arguments) returns (Error) {}
rpc ModPath(stream ModPathArguments) returns (Error) {}
- rpc GetNeighborPolicy(Arguments) returns (ApplyPolicy) {}
+ rpc GetNeighborPolicy(PolicyArguments) returns (ApplyPolicy) {}
rpc ModNeighborPolicy(stream PolicyArguments) returns (stream Error) {}
rpc GetPolicyRoutePolicies(PolicyArguments) returns (stream PolicyDefinition) {}
rpc GetPolicyRoutePolicy(PolicyArguments) returns (PolicyDefinition) {}
@@ -259,13 +259,16 @@ message PolicyDefinition {
repeated Statement statement_list = 2;
}
+enum PolicyType {
+ IN = 0;
+ IMPORT = 1;
+ EXPORT = 2;
+}
+
message ApplyPolicy {
- repeated PolicyDefinition import_policies = 1;
- RouteAction default_import_policy = 2;
- repeated PolicyDefinition export_policies = 3;
- RouteAction default_export_policy = 4;
- repeated PolicyDefinition in_policies = 5;
- RouteAction default_in_policy = 6;
+ PolicyType type = 1;
+ repeated PolicyDefinition policies = 2;
+ RouteAction default = 3;
}
message MrtMessage {
diff --git a/gobgp/cmd/global.go b/gobgp/cmd/global.go
index 72ca9b21..4af4c44a 100644
--- a/gobgp/cmd/global.go
+++ b/gobgp/cmd/global.go
@@ -657,12 +657,19 @@ func NewGlobalCmd() *cobra.Command {
policyCmd := &cobra.Command{
Use: CMD_POLICY,
- Run: func(cmd *cobra.Command, args []string) {
- if err := showNeighborPolicy(nil); err != nil {
- fmt.Println(err)
- os.Exit(1)
- }
- },
+ }
+
+ for _, v := range []string{CMD_IN, CMD_IMPORT, CMD_EXPORT} {
+ cmd := &cobra.Command{
+ Use: v,
+ Run: func(cmd *cobra.Command, args []string) {
+ if err := showNeighborPolicy(nil, cmd.Use); err != nil {
+ fmt.Println(err)
+ os.Exit(1)
+ }
+ },
+ }
+ policyCmd.AddCommand(cmd)
}
globalCmd.AddCommand(ribCmd, policyCmd)
diff --git a/gobgp/cmd/neighbor.go b/gobgp/cmd/neighbor.go
index 2a577461..ca3640fd 100644
--- a/gobgp/cmd/neighbor.go
+++ b/gobgp/cmd/neighbor.go
@@ -22,7 +22,6 @@ import (
api "github.com/osrg/gobgp/api"
"github.com/osrg/gobgp/config"
"github.com/osrg/gobgp/packet"
- "github.com/osrg/gobgp/table"
"github.com/spf13/cobra"
"golang.org/x/net/context"
"io"
@@ -610,19 +609,24 @@ func stateChangeNeighbor(cmd string, remoteIP string, args []string) error {
return err
}
-func showNeighborPolicy(remoteIP net.IP) error {
- rf, err := checkAddressFamily(addr2AddressFamily(remoteIP))
- if err != nil {
- return err
+func showNeighborPolicy(remoteIP net.IP, policyType string) error {
+ p := &api.ApplyPolicy{}
+ switch strings.ToLower(policyType) {
+ case "in":
+ p.Type = api.PolicyType_IN
+ case "import":
+ p.Type = api.PolicyType_IMPORT
+ case "export":
+ p.Type = api.PolicyType_EXPORT
}
r := api.Resource_LOCAL
if remoteIP == nil {
r = api.Resource_GLOBAL
}
- arg := &api.Arguments{
- Rf: uint32(rf),
- Resource: r,
- Name: remoteIP.String(),
+ arg := &api.PolicyArguments{
+ NeighborAddress: remoteIP.String(),
+ ApplyPolicy: p,
+ Resource: r,
}
ap, e := client.GetNeighborPolicy(context.Background(), arg)
@@ -636,24 +640,11 @@ func showNeighborPolicy(remoteIP net.IP) error {
return nil
}
- fmt.Printf("DefaultImportPolicy: %s\n", ap.DefaultImportPolicy)
- fmt.Printf("DefaultExportPolicy: %s\n", ap.DefaultExportPolicy)
- fmt.Printf("DefaultInPolicy: %s\n", ap.DefaultInPolicy)
- fmt.Printf("ImportPolicies:\n")
- for _, inPolicy := range ap.ImportPolicies {
+ fmt.Printf("Default: %s\n", ap.Default)
+ for _, inPolicy := range ap.Policies {
fmt.Printf(" PolicyName %s:\n", inPolicy.PolicyDefinitionName)
showPolicyStatement(2, inPolicy)
}
- fmt.Printf("ExportPolicies:\n")
- for _, outPolicy := range ap.ExportPolicies {
- fmt.Printf(" PolicyName %s:\n", outPolicy.PolicyDefinitionName)
- showPolicyStatement(2, outPolicy)
- }
- fmt.Printf("InPolicies:\n")
- for _, distPolicy := range ap.InPolicies {
- fmt.Printf(" PolicyName %s:\n", distPolicy.PolicyDefinitionName)
- showPolicyStatement(2, distPolicy)
- }
return nil
}
@@ -671,32 +662,31 @@ func parsePolicy(pNames string) []*api.PolicyDefinition {
return policyList
}
-func modNeighborPolicy(remoteIP net.IP, cmdType string, eArg []string) error {
+func modNeighborPolicy(remoteIP net.IP, policyType, cmdType string, eArg []string) error {
var operation api.Operation
- pol := &api.ApplyPolicy{}
+ p := &api.ApplyPolicy{}
+ switch strings.ToLower(policyType) {
+ case "in":
+ p.Type = api.PolicyType_IN
+ case "import":
+ p.Type = api.PolicyType_IMPORT
+ case "export":
+ p.Type = api.PolicyType_EXPORT
+ }
+
switch cmdType {
case CMD_ADD:
- if len(eArg) < 4 {
- return fmt.Errorf("Usage: gobgp neighbor <ipaddr> policy %s {%s|%s|%s} <policies> {%s|%s}", cmdType, CMD_IMPORT, CMD_EXPORT, CMD_IN, table.ROUTE_TYPE_ACCEPT, table.ROUTE_TYPE_REJECT)
+ if len(eArg) < 3 {
+ return fmt.Errorf("Usage: gobgp neighbor <ipaddr> policy %s %s <policies> {%s|%s}", policyType, cmdType, "accept", "reject")
}
- policies := parsePolicy(eArg[1])
- defaultPolicy, err := parseRouteAction(eArg[2])
+ policies := parsePolicy(eArg[0])
+ defaultPolicy, err := parseRouteAction(eArg[1])
if err != nil {
return err
}
- switch eArg[0] {
- case CMD_IMPORT:
- pol.ImportPolicies = policies
- pol.DefaultImportPolicy = defaultPolicy
- case CMD_EXPORT:
- pol.ExportPolicies = policies
- pol.DefaultExportPolicy = defaultPolicy
- case CMD_IN:
- pol.InPolicies = policies
- pol.DefaultInPolicy = defaultPolicy
- }
+ p.Policies = policies
+ p.Default = defaultPolicy
operation = api.Operation_ADD
-
case CMD_DEL:
operation = api.Operation_DEL
}
@@ -705,7 +695,7 @@ func modNeighborPolicy(remoteIP net.IP, cmdType string, eArg []string) error {
Operation: operation,
NeighborAddress: remoteIP.String(),
Name: eArg[0],
- ApplyPolicy: pol,
+ ApplyPolicy: p,
}
stream, err := client.ModNeighborPolicy(context.Background())
if err != nil {
@@ -775,39 +765,48 @@ func NewNeighborCmd() *cobra.Command {
policyCmd := &cobra.Command{
Use: CMD_POLICY,
- Run: func(cmd *cobra.Command, args []string) {
- var err error
- remoteIP := net.ParseIP(args[0])
- if remoteIP == nil {
- err = fmt.Errorf("invalid ip address: %s", args[0])
- } else {
- err = showNeighborPolicy(remoteIP)
- }
- if err != nil {
- fmt.Println(err)
- os.Exit(1)
- }
- },
}
- for _, v := range []string{CMD_ADD, CMD_DEL} {
+ for _, v := range []string{CMD_IN, CMD_IMPORT, CMD_EXPORT} {
cmd := &cobra.Command{
Use: v,
Run: func(cmd *cobra.Command, args []string) {
var err error
- remoteIP := net.ParseIP(args[len(args)-1])
+ remoteIP := net.ParseIP(args[0])
if remoteIP == nil {
- fmt.Println("invalid ip address:", args[len(args)-1])
- os.Exit(1)
+ err = fmt.Errorf("invalid ip address: %s", args[0])
+ } else {
+ err = showNeighborPolicy(remoteIP, cmd.Use)
}
- err = modNeighborPolicy(remoteIP, cmd.Use, args)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
+
},
}
+
+ for _, w := range []string{CMD_ADD, CMD_DEL} {
+ subcmd := &cobra.Command{
+ Use: w,
+ Run: func(subcmd *cobra.Command, args []string) {
+ remoteIP := net.ParseIP(args[len(args)-1])
+ if remoteIP == nil {
+ fmt.Println("invalid ip address:", args[len(args)-1])
+ os.Exit(1)
+ }
+ err := modNeighborPolicy(remoteIP, cmd.Use, subcmd.Use, args)
+ if err != nil {
+ fmt.Println(err)
+ os.Exit(1)
+ }
+ },
+ }
+ cmd.AddCommand(subcmd)
+ }
+
policyCmd.AddCommand(cmd)
+
}
neighborCmdImpl.AddCommand(policyCmd)
diff --git a/server/grpc_server.go b/server/grpc_server.go
index b3da4b3d..59d1819c 100644
--- a/server/grpc_server.go
+++ b/server/grpc_server.go
@@ -41,12 +41,7 @@ const (
REQ_NEIGHBOR_ENABLE
REQ_NEIGHBOR_DISABLE
REQ_NEIGHBOR_POLICY
- REQ_NEIGHBOR_POLICY_ADD_IMPORT
- REQ_NEIGHBOR_POLICY_ADD_EXPORT
- REQ_NEIGHBOR_POLICY_ADD_IN
- REQ_NEIGHBOR_POLICY_DEL_IMPORT
- REQ_NEIGHBOR_POLICY_DEL_EXPORT
- REQ_NEIGHBOR_POLICY_DEL_IN
+ REQ_MOD_NEIGHBOR_POLICY
REQ_GLOBAL_RIB
REQ_POLICY_PREFIX
REQ_POLICY_PREFIXES
@@ -269,16 +264,18 @@ func (s *Server) ModPath(stream api.GobgpApi_ModPathServer) error {
return err
}
-func (s *Server) GetNeighborPolicy(ctx context.Context, arg *api.Arguments) (*api.ApplyPolicy, error) {
- if arg.Resource != api.Resource_LOCAL && arg.Resource != api.Resource_GLOBAL {
+func (s *Server) GetNeighborPolicy(ctx context.Context, arg *api.PolicyArguments) (*api.ApplyPolicy, error) {
+ r := 0
+ switch arg.Resource {
+ case api.Resource_GLOBAL:
+ r = REQ_GLOBAL_POLICY
+ case api.Resource_POLICY_NEIGHBOR:
+ r = REQ_NEIGHBOR_POLICY
+ default:
return nil, fmt.Errorf("unsupported resource: %s", arg.Resource)
}
- var req *GrpcRequest
- if arg.Resource == api.Resource_LOCAL {
- req = NewGrpcRequest(REQ_NEIGHBOR_POLICY, arg.Name, bgp.RouteFamily(arg.Rf), nil)
- } else {
- req = NewGrpcRequest(REQ_GLOBAL_POLICY, "", bgp.RouteFamily(arg.Rf), nil)
- }
+
+ req := NewGrpcRequest(r, arg.NeighborAddress, bgp.RouteFamily(0), arg)
s.bgpServerCh <- req
res := <-req.ResponseCh
@@ -298,32 +295,7 @@ func (s *Server) ModNeighborPolicy(stream api.GobgpApi_ModNeighborPolicyServer)
return err
}
- if arg.Resource != api.Resource_POLICY_ROUTEPOLICY {
- return fmt.Errorf("unsupported resource: %s", arg.Resource)
- }
- var rf bgp.RouteFamily
- var reqType int
- switch arg.Operation {
- case api.Operation_ADD:
- switch arg.Name {
- case "import":
- reqType = REQ_NEIGHBOR_POLICY_ADD_IMPORT
- case "export":
- reqType = REQ_NEIGHBOR_POLICY_ADD_EXPORT
- case "in":
- reqType = REQ_NEIGHBOR_POLICY_ADD_IN
- }
- case api.Operation_DEL:
- switch arg.Name {
- case "import":
- reqType = REQ_NEIGHBOR_POLICY_DEL_IMPORT
- case "export":
- reqType = REQ_NEIGHBOR_POLICY_DEL_EXPORT
- case "in":
- reqType = REQ_NEIGHBOR_POLICY_DEL_IN
- }
- }
- req := NewGrpcRequest(reqType, arg.NeighborAddress, rf, arg.ApplyPolicy)
+ req := NewGrpcRequest(REQ_MOD_NEIGHBOR_POLICY, arg.NeighborAddress, bgp.RouteFamily(0), arg)
s.bgpServerCh <- req
res := <-req.ResponseCh
if err := res.Err(); err != nil {
diff --git a/server/server.go b/server/server.go
index 35f26a86..77d8fb22 100644
--- a/server/server.go
+++ b/server/server.go
@@ -1547,114 +1547,104 @@ func (server *BgpServer) handleGrpc(grpcReq *GrpcRequest) []*SenderMsg {
close(grpcReq.ResponseCh)
case REQ_NEIGHBOR_POLICY, REQ_GLOBAL_POLICY:
- var in, imp, exp []*api.PolicyDefinition
- var inD, impD, expD api.RouteAction
-
- extract := func(policyNames []string) []*api.PolicyDefinition {
- pdList := server.routingPolicy.PolicyDefinitions.PolicyDefinitionList
- df := server.routingPolicy.DefinedSets
- extracted := []*api.PolicyDefinition{}
- for _, policyName := range policyNames {
- match := false
- for _, pd := range pdList {
- if policyName == pd.Name {
- match = true
- extracted = append(extracted, table.PolicyDefinitionToApiStruct(pd, df))
- break
- }
- }
- if !match {
- extracted = append(extracted, &api.PolicyDefinition{PolicyDefinitionName: policyName})
- }
- }
- return extracted
- }
-
- if grpcReq.RequestType == REQ_NEIGHBOR_POLICY {
+ arg := grpcReq.Data.(*api.PolicyArguments)
+ var names []string
+ def := api.RouteAction_REJECT
+ var applyPolicy config.ApplyPolicy
+ switch grpcReq.RequestType {
+ case REQ_NEIGHBOR_POLICY:
peer, err := server.checkNeighborRequest(grpcReq)
if err != nil {
break
}
- // Add importpolies that has been set in the configuration file to the list.
- // However, peer haven't target importpolicy when add PolicyDefinition of name only to the list.
- conImportPolicyNames := peer.conf.ApplyPolicy.ApplyPolicyConfig.ImportPolicy
- imp = extract(conImportPolicyNames)
-
- // Add importpolies that has been set in the configuration file to the list.
- // However, peer haven't target importpolicy when add PolicyDefinition of name only to the list.
- conExportPolicyNames := peer.conf.ApplyPolicy.ApplyPolicyConfig.ExportPolicy
- exp = extract(conExportPolicyNames)
-
- inPolicyNames := peer.conf.ApplyPolicy.ApplyPolicyConfig.InPolicy
- in = extract(inPolicyNames)
-
- impD = peer.GetDefaultPolicy(table.POLICY_DIRECTION_IMPORT).ToApiStruct()
- expD = peer.GetDefaultPolicy(table.POLICY_DIRECTION_EXPORT).ToApiStruct()
- inD = peer.GetDefaultPolicy(table.POLICY_DIRECTION_IN).ToApiStruct()
- } else {
- names := server.bgpConfig.Global.ApplyPolicy.ApplyPolicyConfig.ImportPolicy
- imp = extract(names)
-
- names = server.bgpConfig.Global.ApplyPolicy.ApplyPolicyConfig.ExportPolicy
- exp = extract(names)
+ applyPolicy = peer.conf.ApplyPolicy
+ case REQ_GLOBAL_RIB:
+ applyPolicy = server.bgpConfig.Global.ApplyPolicy
+ default:
+ }
+ switch arg.ApplyPolicy.Type {
+ case api.PolicyType_IMPORT:
+ names = applyPolicy.ApplyPolicyConfig.ImportPolicy
+ if applyPolicy.ApplyPolicyConfig.DefaultImportPolicy == config.DEFAULT_POLICY_TYPE_ACCEPT_ROUTE {
+ def = api.RouteAction_ACCEPT
+ }
+ case api.PolicyType_EXPORT:
+ names = applyPolicy.ApplyPolicyConfig.ExportPolicy
+ if applyPolicy.ApplyPolicyConfig.DefaultExportPolicy == config.DEFAULT_POLICY_TYPE_ACCEPT_ROUTE {
+ def = api.RouteAction_ACCEPT
+ }
+ case api.PolicyType_IN:
+ names = applyPolicy.ApplyPolicyConfig.InPolicy
+ if applyPolicy.ApplyPolicyConfig.DefaultInPolicy == config.DEFAULT_POLICY_TYPE_ACCEPT_ROUTE {
+ def = api.RouteAction_ACCEPT
+ }
+ }
+ policies := make([]*api.PolicyDefinition, 0, len(names))
- impD = server.globalRib.GetDefaultPolicy(table.POLICY_DIRECTION_IMPORT).ToApiStruct()
- expD = server.globalRib.GetDefaultPolicy(table.POLICY_DIRECTION_EXPORT).ToApiStruct()
+ pdList := server.routingPolicy.PolicyDefinitions.PolicyDefinitionList
+ df := server.routingPolicy.DefinedSets
+ for _, name := range names {
+ match := false
+ for _, pd := range pdList {
+ if name == pd.Name {
+ match = true
+ policies = append(policies, table.PolicyDefinitionToApiStruct(pd, df))
+ break
+ }
+ }
+ if !match {
+ policies = append(policies, &api.PolicyDefinition{PolicyDefinitionName: name})
+ }
}
result := &GrpcResponse{
Data: &api.ApplyPolicy{
- DefaultImportPolicy: impD,
- ImportPolicies: imp,
- DefaultExportPolicy: expD,
- ExportPolicies: exp,
- DefaultInPolicy: inD,
- InPolicies: in,
+ Policies: policies,
+ Default: def,
},
}
grpcReq.ResponseCh <- result
close(grpcReq.ResponseCh)
- case REQ_NEIGHBOR_POLICY_ADD_IMPORT, REQ_NEIGHBOR_POLICY_ADD_EXPORT, REQ_NEIGHBOR_POLICY_ADD_IN,
- REQ_NEIGHBOR_POLICY_DEL_IMPORT, REQ_NEIGHBOR_POLICY_DEL_EXPORT, REQ_NEIGHBOR_POLICY_DEL_IN:
+ case REQ_MOD_NEIGHBOR_POLICY:
peer, err := server.checkNeighborRequest(grpcReq)
if err != nil {
break
}
result := &GrpcResponse{}
- reqApplyPolicy := grpcReq.Data.(*api.ApplyPolicy)
+ arg := grpcReq.Data.(*api.PolicyArguments)
reqPolicyMap := server.policyMap
- applyPolicy := &peer.conf.ApplyPolicy.ApplyPolicyConfig
- var defInPolicy, defOutPolicy, defDistPolicy config.DefaultPolicyType
- if grpcReq.RequestType == REQ_NEIGHBOR_POLICY_ADD_IMPORT {
- if reqApplyPolicy.DefaultImportPolicy != api.RouteAction_ACCEPT {
- defInPolicy = config.DEFAULT_POLICY_TYPE_REJECT_ROUTE
- }
- applyPolicy.DefaultImportPolicy = defInPolicy
- applyPolicy.ImportPolicy = table.PoliciesToString(reqApplyPolicy.ImportPolicies)
- } else if grpcReq.RequestType == REQ_NEIGHBOR_POLICY_ADD_EXPORT {
- if reqApplyPolicy.DefaultExportPolicy != api.RouteAction_ACCEPT {
- defOutPolicy = config.DEFAULT_POLICY_TYPE_REJECT_ROUTE
- }
- applyPolicy.DefaultExportPolicy = defOutPolicy
- applyPolicy.ExportPolicy = table.PoliciesToString(reqApplyPolicy.ExportPolicies)
- } else if grpcReq.RequestType == REQ_NEIGHBOR_POLICY_ADD_IN {
- if reqApplyPolicy.DefaultInPolicy != api.RouteAction_ACCEPT {
- defDistPolicy = config.DEFAULT_POLICY_TYPE_REJECT_ROUTE
- }
- applyPolicy.DefaultInPolicy = defDistPolicy
- applyPolicy.InPolicy = table.PoliciesToString(reqApplyPolicy.InPolicies)
- } else if grpcReq.RequestType == REQ_NEIGHBOR_POLICY_DEL_IMPORT {
- applyPolicy.DefaultImportPolicy = config.DEFAULT_POLICY_TYPE_ACCEPT_ROUTE
- applyPolicy.ImportPolicy = make([]string, 0)
- } else if grpcReq.RequestType == REQ_NEIGHBOR_POLICY_DEL_EXPORT {
- applyPolicy.DefaultExportPolicy = config.DEFAULT_POLICY_TYPE_ACCEPT_ROUTE
- applyPolicy.ExportPolicy = make([]string, 0)
- } else if grpcReq.RequestType == REQ_NEIGHBOR_POLICY_DEL_IN {
- applyPolicy.DefaultInPolicy = config.DEFAULT_POLICY_TYPE_ACCEPT_ROUTE
- applyPolicy.InPolicy = make([]string, 0)
+ applyPolicy := peer.conf.ApplyPolicy.ApplyPolicyConfig
+ def := config.DEFAULT_POLICY_TYPE_ACCEPT_ROUTE
+ switch arg.Operation {
+ case api.Operation_ADD:
+ if arg.ApplyPolicy.Default != api.RouteAction_REJECT {
+ def = config.DEFAULT_POLICY_TYPE_REJECT_ROUTE
+ }
+ switch arg.ApplyPolicy.Type {
+ case api.PolicyType_IMPORT:
+ applyPolicy.DefaultImportPolicy = def
+ applyPolicy.ImportPolicy = table.PoliciesToString(arg.ApplyPolicy.Policies)
+ case api.PolicyType_EXPORT:
+ applyPolicy.DefaultExportPolicy = def
+ applyPolicy.ExportPolicy = table.PoliciesToString(arg.ApplyPolicy.Policies)
+ case api.PolicyType_IN:
+ applyPolicy.DefaultInPolicy = def
+ applyPolicy.InPolicy = table.PoliciesToString(arg.ApplyPolicy.Policies)
+ }
+ case api.Operation_DEL:
+ switch arg.ApplyPolicy.Type {
+ case api.PolicyType_IMPORT:
+ applyPolicy.DefaultImportPolicy = def
+ applyPolicy.ImportPolicy = []string{}
+ case api.PolicyType_EXPORT:
+ applyPolicy.DefaultExportPolicy = def
+ applyPolicy.ExportPolicy = []string{}
+ case api.PolicyType_IN:
+ applyPolicy.DefaultInPolicy = def
+ applyPolicy.InPolicy = []string{}
+ }
}
-
peer.setPolicy(reqPolicyMap)
grpcReq.ResponseCh <- result