025d9887d43c304225b9260f210667d764571415
[groupbasedpolicy.git] / renderers / ofoverlay / src / main / java / org / opendaylight / groupbasedpolicy / renderer / ofoverlay / sf / SubjectFeatures.java
1 package org.opendaylight.groupbasedpolicy.renderer.ofoverlay.sf;
2 /*
3  * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
4  *
5  * This program and the accompanying materials are made available under the
6  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
7  * and is available at http://www.eclipse.org/legal/epl-v10.html
8  */
9
10
11
12 import java.util.List;
13 import java.util.Map;
14
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.ActionDefinitionId;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.ClassifierDefinitionId;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.SubjectFeatureDefinitions;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.SubjectFeatureDefinitionsBuilder;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.subject.feature.definitions.ActionDefinition;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.subject.feature.definitions.ClassifierDefinition;
21
22 import com.google.common.base.Function;
23 import com.google.common.collect.Collections2;
24 import com.google.common.collect.ImmutableList;
25 import com.google.common.collect.ImmutableMap;
26
27 /**
28  * Defines the subject features that are supported by the OF overlay renderer
29  */
30 public class SubjectFeatures {
31     private static final Map<ClassifierDefinitionId, Classifier> classifiers =
32             ImmutableMap.<ClassifierDefinitionId, Classifier>
33                 of(EtherTypeClassifier.ID, Classifier.ETHER_TYPE_CL,
34                    IpProtoClassifier.ID, Classifier.IP_PROTO_CL,
35                    L4Classifier.ID, Classifier.L4_CL);
36
37     private static final List<ClassifierDefinition> classifierDefs =
38             ImmutableList.copyOf(Collections2.transform(classifiers.values(),
39                 new Function<Classifier, ClassifierDefinition>() {
40                     @Override
41                     public ClassifierDefinition apply(Classifier input) {
42                         return input.getClassDef();
43                     }
44                 }
45             ));
46
47     private static final Map<ActionDefinitionId, Action> actions =
48             ImmutableMap.<ActionDefinitionId, Action>
49                 of(AllowAction.ID, new AllowAction(),
50                    ChainAction.ID, new ChainAction());
51
52     private static final List<ActionDefinition> actionDefs =
53             ImmutableList.copyOf(Collections2.transform(actions.values(),
54                 new Function<Action, ActionDefinition>() {
55                     @Override
56                     public ActionDefinition apply(Action input) {
57                         return input.getActionDef();
58                     }
59                 }
60              ));
61
62     public static final SubjectFeatureDefinitions OF_OVERLAY_FEATURES =
63             new SubjectFeatureDefinitionsBuilder()
64                 .setActionDefinition(actionDefs)
65                 .setClassifierDefinition(classifierDefs)
66                 .build();
67
68     /**
69      * Get the {@link Classifier} associated with the given
70      * {@link ClassifierDefinitionId}
71      * @param id the {@link ClassifierDefinitionId} to look up
72      * @return the {@link Classifier} if one exists, or <code>null</code>
73      * otherwise
74      */
75     public static Classifier getClassifier(ClassifierDefinitionId id) {
76         return classifiers.get(id);
77     }
78
79     public static Map<ActionDefinitionId, Action> getActions() {
80         return actions;
81     }
82
83     /**
84      * Get the {@link Action} associated with the given
85      * {@link ActionDefinitionId}
86      * @param id the {@link ActionDefinitionId} to look up
87      * @return the {@link Action} if one exists, or <code>null</code>
88      * otherwise
89      */
90     public static Action getAction(ActionDefinitionId id) {
91         return actions.get(id);
92     }
93 }