summaryrefslogtreecommitdiffhomepage
path: root/table/policy.go
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/policy.go
parent204eacc5c0503cecc796a74fd0c1948ad6a28051 (diff)
api: support policy assignment modification via grpc
Signed-off-by: ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp>
Diffstat (limited to 'table/policy.go')
-rw-r--r--table/policy.go45
1 files changed, 44 insertions, 1 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 {