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