Added SFs, EP handling, Resolved Policy for IOVisorRenderer
[groupbasedpolicy.git] / renderers / iovisor / src / main / java / org / opendaylight / groupbasedpolicy / renderer / iovisor / sf / SubjectFeatures.java
diff --git a/renderers/iovisor/src/main/java/org/opendaylight/groupbasedpolicy/renderer/iovisor/sf/SubjectFeatures.java b/renderers/iovisor/src/main/java/org/opendaylight/groupbasedpolicy/renderer/iovisor/sf/SubjectFeatures.java
new file mode 100755 (executable)
index 0000000..94f3813
--- /dev/null
@@ -0,0 +1,90 @@
+/*
+ * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.groupbasedpolicy.renderer.iovisor.sf;
+
+import java.util.List;
+import java.util.Map;
+
+import org.opendaylight.groupbasedpolicy.api.sf.AllowActionDefinition;
+import org.opendaylight.groupbasedpolicy.api.sf.EtherTypeClassifierDefinition;
+import org.opendaylight.groupbasedpolicy.api.sf.IpProtoClassifierDefinition;
+import org.opendaylight.groupbasedpolicy.api.sf.L4ClassifierDefinition;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.ActionDefinitionId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.ClassifierDefinitionId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.SubjectFeatureDefinitions;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.SubjectFeatureDefinitionsBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.subject.feature.definitions.ActionDefinition;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.subject.feature.definitions.ClassifierDefinition;
+
+import com.google.common.base.Function;
+import com.google.common.collect.Collections2;
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableMap;
+
+/**
+ * Defines the subject features that are supported by the OF overlay renderer
+ */
+public class SubjectFeatures {
+
+    private static final Map<ClassifierDefinitionId, Classifier> classifiers =
+            ImmutableMap.of(EtherTypeClassifierDefinition.ID, Classifier.ETHER_TYPE_CL, IpProtoClassifierDefinition.ID,
+                    Classifier.IP_PROTO_CL, L4ClassifierDefinition.ID, Classifier.L4_CL);
+
+    private static final List<ClassifierDefinition> classifierDefs = ImmutableList
+        .copyOf(Collections2.transform(classifiers.values(), new Function<Classifier, ClassifierDefinition>() {
+
+            @Override
+            public ClassifierDefinition apply(Classifier input) {
+                return input.getClassifierDefinition();
+            }
+        }));
+
+    private static final Map<ActionDefinitionId, Action> actions =
+            ImmutableMap.<ActionDefinitionId, Action>of(AllowActionDefinition.ID, new AllowAction());
+
+    private static final List<ActionDefinition> actionDefs =
+            ImmutableList.copyOf(Collections2.transform(actions.values(), new Function<Action, ActionDefinition>() {
+
+                @Override
+                public ActionDefinition apply(Action input) {
+                    return input.getActionDef();
+                }
+            }));
+
+    public static final SubjectFeatureDefinitions IOVISOR_FEATURES = new SubjectFeatureDefinitionsBuilder()
+        .setActionDefinition(actionDefs).setClassifierDefinition(classifierDefs).build();
+
+    /**
+     * Get the {@link Classifier} associated with the given
+     * {@link ClassifierDefinitionId}
+     *
+     * @param id the {@link ClassifierDefinitionId} to look up
+     * @return the {@link Classifier} if one exists, or <code>null</code>
+     *         otherwise
+     */
+    public static Classifier getClassifier(ClassifierDefinitionId id) {
+        return classifiers.get(id);
+    }
+
+    public static Map<ActionDefinitionId, Action> getActions() {
+        return actions;
+    }
+
+    /**
+     * Get the {@link Action} associated with the given
+     * {@link ActionDefinitionId}
+     *
+     * @param id the {@link ActionDefinitionId} to look up
+     * @return the {@link Action} if one exists, or <code>null</code>
+     *         otherwise
+     */
+    public static Action getAction(ActionDefinitionId id) {
+        return actions.get(id);
+    }
+}