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