Implementation of IP address classifier.
[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                    IpAddressClassifier.ID, new IpAddressClassifier());
39
40     private static final List<ClassifierDefinition> classifierDefs =
41             ImmutableList.copyOf(Collections2.transform(classifiers.values(), 
42                 new Function<Classifier, ClassifierDefinition>() {
43                     @Override
44                     public ClassifierDefinition apply(Classifier input) {
45                         return input.getClassDef();
46                     }
47                 }
48             ));
49     
50     private static final Map<ActionDefinitionId, Action> actions =
51             ImmutableMap.<ActionDefinitionId, Action>
52                 of(AllowAction.ID, new AllowAction());
53
54     public static final List<ActionDefinition> actionDefs =
55             ImmutableList.copyOf(Collections2.transform(actions.values(),
56                 new Function<Action, ActionDefinition>() {
57                     @Override
58                     public ActionDefinition apply(Action input) {
59                         return input.getActionDef();
60                     }
61                 }
62              ));
63
64
65     public static final SubjectFeatureDefinitions OF_OVERLAY_FEATURES =
66             new SubjectFeatureDefinitionsBuilder()
67                 .setActionDefinition(actionDefs)
68                 .setClassifierDefinition(classifierDefs)
69                 .build();
70
71     /**
72      * Get the {@link Classifier} associated with the given 
73      * {@link ClassifierDefinitionId}
74      * @param id the {@link ClassifierDefinitionId} to look up
75      * @return the {@link Classifier} if one exists, or <code>null</code> 
76      * otherwise
77      */
78     public static Classifier getClassifier(ClassifierDefinitionId id) {
79         return classifiers.get(id);
80     }
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 }