3840f3f8f34e3d7017ff12a5a9dc0ea4669eb017
[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.ClassifierDefinitionId;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.SubjectFeatureDefinitions;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.SubjectFeatureDefinitionsBuilder;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.subject.feature.definitions.ActionDefinition;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.subject.feature.definitions.ClassifierDefinition;
20
21 import com.google.common.base.Function;
22 import com.google.common.collect.Collections2;
23 import com.google.common.collect.ImmutableList;
24 import com.google.common.collect.ImmutableMap;
25
26 /**
27  * Defines the subject features that are supported by the OF overlay renderer
28  */
29 public class SubjectFeatures {
30     private static final Map<ClassifierDefinitionId, Classifier> classifiers =
31             ImmutableMap.<ClassifierDefinitionId, Classifier>
32                 of(EtherTypeClassifier.ID, Classifier.ETHER_TYPE_CL,
33                    IpProtoClassifier.ID, Classifier.IP_PROTO_CL,
34                    L4Classifier.ID, Classifier.L4_CL);
35
36     private static final List<ClassifierDefinition> classifierDefs =
37             ImmutableList.copyOf(Collections2.transform(classifiers.values(),
38                 new Function<Classifier, ClassifierDefinition>() {
39                     @Override
40                     public ClassifierDefinition apply(Classifier input) {
41                         return input.getClassDef();
42                     }
43                 }
44             ));
45
46     private static final Map<ActionDefinitionId, Action> actions =
47             ImmutableMap.<ActionDefinitionId, Action>
48                 of(AllowAction.ID, new AllowAction());
49
50     public static final List<ActionDefinition> actionDefs =
51             ImmutableList.copyOf(Collections2.transform(actions.values(),
52                 new Function<Action, ActionDefinition>() {
53                     @Override
54                     public ActionDefinition apply(Action input) {
55                         return input.getActionDef();
56                     }
57                 }
58              ));
59
60     public static final SubjectFeatureDefinitions OF_OVERLAY_FEATURES =
61             new SubjectFeatureDefinitionsBuilder()
62                 .setActionDefinition(actionDefs)
63                 .setClassifierDefinition(classifierDefs)
64                 .build();
65
66     /**
67      * Get the {@link Classifier} associated with the given
68      * {@link ClassifierDefinitionId}
69      * @param id the {@link ClassifierDefinitionId} to look up
70      * @return the {@link Classifier} if one exists, or <code>null</code>
71      * otherwise
72      */
73     public static Classifier getClassifier(ClassifierDefinitionId id) {
74         return classifiers.get(id);
75     }
76
77     /**
78      * Get the {@link Action} associated with the given
79      * {@link ActionDefinitionId}
80      * @param id the {@link ActionDefinitionId} to look up
81      * @return the {@link Action} if one exists, or <code>null</code>
82      * otherwise
83      */
84     public static Action getAction(ActionDefinitionId id) {
85         return actions.get(id);
86     }
87 }