ffe0b9d7397f675fbe44cd0ea6f422b5dbee114a
[groupbasedpolicy.git] / neutron-mapper / src / main / java / org / opendaylight / groupbasedpolicy / neutron / mapper / mapping / rule / SingleClassifierRule.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.neutron.mapper.mapping.rule;
10
11
12 import java.util.List;
13
14 import javax.annotation.concurrent.Immutable;
15
16 import org.opendaylight.neutron.spi.NeutronSecurityRule;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.has.action.refs.ActionRef;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.has.classifier.refs.ClassifierRef;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.policy.contract.subject.Rule;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.policy.contract.subject.RuleBuilder;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.policy.subject.feature.instances.ClassifierInstance;
22
23 import com.google.common.collect.ImmutableList;
24
25 @Immutable
26 public class SingleClassifierRule {
27
28     private final ClassifierInstance classifierInstance;
29     private final ClassifierRef classifierRef;
30     private final Rule rule;
31
32     public SingleClassifierRule(NeutronSecurityRule secRule, int ruleOrder, List<ActionRef> actions) {
33         classifierInstance = SecRuleEntityDecoder.getClassifierInstance(secRule);
34         classifierRef = SecRuleEntityDecoder.getClassifierRef(secRule);
35         rule = createRule(ruleOrder, secRule, actions);
36     }
37
38     private Rule createRule(int order, NeutronSecurityRule secRule, List<ActionRef> actions) {
39         return new RuleBuilder().setName(SecRuleNameDecoder.getRuleName(secRule))
40             .setOrder(order)
41             .setActionRef(actions)
42             .setClassifierRef(ImmutableList.of(classifierRef))
43             .build();
44     }
45
46     public ClassifierInstance getClassifierInstance() {
47         return classifierInstance;
48     }
49
50     public ClassifierRef getClassifierRef() {
51         return classifierRef;
52     }
53
54     public Rule getRule() {
55         return rule;
56     }
57
58 }