Added range type to subject-feature-definition/parameter
[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     public static final ActionDefinition ALLOW = 
50             new ActionDefinitionBuilder()
51                 .setId(new ActionDefinitionId("f942e8fd-e957-42b7-bd18-f73d11266d17"))
52                 .setName(new ActionName("allow"))
53                 .setDescription(new Description("Allow the specified traffic to pass"))
54                 .build();
55
56     public static final SubjectFeatureDefinitions OF_OVERLAY_FEATURES =
57             new SubjectFeatureDefinitionsBuilder()
58                 .setActionDefinition(ImmutableList.of(ALLOW))
59                 .setClassifierDefinition(classifierDefs)
60                 .build();
61
62     /**
63      * Get the {@link Classifier} associated with the given 
64      * {@link ClassifierDefinitionId}
65      * @param id the {@link ClassifierDefinitionId} to look up
66      * @return the {@link Classifier} if one exists, or <code>null</code> 
67      * otherwise
68      */
69     public static Classifier getClassifier(ClassifierDefinitionId id) {
70         return classifiers.get(id);
71     }
72                                            
73 }