summaryrefslogtreecommitdiffhomepage
path: root/table
diff options
context:
space:
mode:
authorISHIDA Wataru <ishida.wataru@lab.ntt.co.jp>2015-10-19 14:39:04 +0900
committerFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2015-10-20 10:33:10 +0900
commitf634b5035729485105d54c25198d36542337aea5 (patch)
tree1c39317df070390f397240868e414b78356c5cd0 /table
parent204eacc5c0503cecc796a74fd0c1948ad6a28051 (diff)
api: support policy assignment modification via grpc
Signed-off-by: ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp>
Diffstat (limited to 'table')
-rw-r--r--table/policy.go45
-rw-r--r--table/table_manager.go65
2 files changed, 71 insertions, 39 deletions
diff --git a/table/policy.go b/table/policy.go
index 5829fc98..92273467 100644
--- a/table/policy.go
+++ b/table/policy.go
@@ -48,10 +48,21 @@ const (
ROUTE_TYPE_REJECT
)
+func (t RouteType) ToApiStruct() api.RouteAction {
+ switch t {
+ case ROUTE_TYPE_ACCEPT:
+ return api.RouteAction_ACCEPT
+ case ROUTE_TYPE_REJECT:
+ return api.RouteAction_REJECT
+ }
+ return api.RouteAction_NONE
+}
+
type PolicyDirection int
const (
- POLICY_DIRECTION_IMPORT PolicyDirection = iota
+ POLICY_DIRECTION_NONE PolicyDirection = iota
+ POLICY_DIRECTION_IMPORT
POLICY_DIRECTION_EXPORT
POLICY_DIRECTION_IN
)
@@ -2352,6 +2363,38 @@ type RoutingPolicy struct {
StatementMap map[string]*Statement
}
+func (r *RoutingPolicy) GetAssignmentFromConfig(dir PolicyDirection, a config.ApplyPolicy) ([]*Policy, RouteType, error) {
+ var names []string
+ var cdef config.DefaultPolicyType
+ def := ROUTE_TYPE_ACCEPT
+ c := a.ApplyPolicyConfig
+ switch dir {
+ case POLICY_DIRECTION_IN:
+ names = c.InPolicy
+ cdef = c.DefaultInPolicy
+ case POLICY_DIRECTION_IMPORT:
+ names = c.ImportPolicy
+ cdef = c.DefaultImportPolicy
+ case POLICY_DIRECTION_EXPORT:
+ names = c.ExportPolicy
+ cdef = c.DefaultExportPolicy
+ default:
+ return nil, def, fmt.Errorf("invalid policy direction")
+ }
+ if cdef == config.DEFAULT_POLICY_TYPE_REJECT_ROUTE {
+ def = ROUTE_TYPE_REJECT
+ }
+ ps := make([]*Policy, 0, len(names))
+ for _, name := range names {
+ p, ok := r.PolicyMap[name]
+ if !ok {
+ return nil, def, fmt.Errorf("not found policy %s", name)
+ }
+ ps = append(ps, p)
+ }
+ return ps, def, nil
+}
+
func (r *RoutingPolicy) InUse(d DefinedSet) bool {
name := d.Name()
for _, p := range r.PolicyMap {
diff --git a/table/table_manager.go b/table/table_manager.go
index a8d9e8ff..8ca127d6 100644
--- a/table/table_manager.go
+++ b/table/table_manager.go
@@ -19,7 +19,6 @@ import (
"bytes"
"fmt"
log "github.com/Sirupsen/logrus"
- "github.com/osrg/gobgp/config"
"github.com/osrg/gobgp/packet"
"net"
"reflect"
@@ -115,9 +114,9 @@ type TableManager struct {
maxLabel uint32
nextLabel uint32
importPolicies []*Policy
- defaultImportPolicy config.DefaultPolicyType
+ defaultImportPolicy RouteType
exportPolicies []*Policy
- defaultExportPolicy config.DefaultPolicyType
+ defaultExportPolicy RouteType
}
func NewTableManager(owner string, rfList []bgp.RouteFamily, minLabel, maxLabel uint32) *TableManager {
@@ -135,35 +134,6 @@ func NewTableManager(owner string, rfList []bgp.RouteFamily, minLabel, maxLabel
return t
}
-func (manager *TableManager) SetPolicy(c config.ApplyPolicy, p map[string]*Policy) {
- manager.defaultImportPolicy = c.ApplyPolicyConfig.DefaultImportPolicy
- manager.defaultExportPolicy = c.ApplyPolicyConfig.DefaultExportPolicy
- f := func(dir string, arg []string) []*Policy {
- ret := make([]*Policy, 0, len(arg))
- for _, name := range arg {
- pol, ok := p[name]
- if !ok {
- log.WithFields(log.Fields{
- "Topic": "table",
- "Key": manager.owner,
- "PolicyName": name,
- }).Warnf("not found %s. failed to set %s policy", name, dir)
- continue
- }
- ret = append(ret, pol)
- log.WithFields(log.Fields{
- "Topic": "table",
- "Key": manager.owner,
- "PolicyName": name,
- }).Infof("%s policy installed", dir)
- }
- return ret
- }
- manager.importPolicies = f("import", c.ApplyPolicyConfig.ImportPolicy)
- manager.exportPolicies = f("export", c.ApplyPolicyConfig.ExportPolicy)
-
-}
-
func (manager *TableManager) GetPolicy(d PolicyDirection) []*Policy {
switch d {
case POLICY_DIRECTION_IMPORT:
@@ -174,19 +144,38 @@ func (manager *TableManager) GetPolicy(d PolicyDirection) []*Policy {
return nil
}
+func (manager *TableManager) SetPolicy(d PolicyDirection, policies []*Policy) error {
+ switch d {
+ case POLICY_DIRECTION_IMPORT:
+ manager.importPolicies = policies
+ case POLICY_DIRECTION_EXPORT:
+ manager.exportPolicies = policies
+ default:
+ return fmt.Errorf("unsupported policy type: %d", d)
+ }
+ return nil
+}
+
func (manager *TableManager) GetDefaultPolicy(d PolicyDirection) RouteType {
- var def config.DefaultPolicyType
switch d {
case POLICY_DIRECTION_IMPORT:
- def = manager.defaultImportPolicy
+ return manager.defaultImportPolicy
case POLICY_DIRECTION_EXPORT:
- def = manager.defaultExportPolicy
+ return manager.defaultExportPolicy
}
+ return ROUTE_TYPE_NONE
+}
- if def == config.DEFAULT_POLICY_TYPE_ACCEPT_ROUTE {
- return ROUTE_TYPE_ACCEPT
+func (manager *TableManager) SetDefaultPolicy(d PolicyDirection, typ RouteType) error {
+ switch d {
+ case POLICY_DIRECTION_IMPORT:
+ manager.defaultImportPolicy = typ
+ case POLICY_DIRECTION_EXPORT:
+ manager.defaultExportPolicy = typ
+ default:
+ return fmt.Errorf("unsupported policy type: %d", d)
}
- return ROUTE_TYPE_REJECT
+ return nil
}
func (manager *TableManager) ApplyPolicy(d PolicyDirection, paths []*Path) []*Path {