Fix checkstyle
[genius.git] / mdsalutil / mdsalutil-api / src / main / java / org / opendaylight / genius / mdsalutil / FlowEntity.java
1 /*
2  * Copyright (c) 2016 Ericsson India Global Services Pvt Ltd. 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 package org.opendaylight.genius.mdsalutil;
9
10 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
11 import java.math.BigInteger;
12 import java.util.List;
13 import org.eclipse.jdt.annotation.Nullable;
14 import org.immutables.value.Value.Default;
15 import org.immutables.value.Value.Immutable;
16 import org.opendaylight.genius.infra.OpenDaylightImmutableStyle;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowId;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowBuilder;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowKey;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowCookie;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowModFlags;
22
23 @Immutable
24 @OpenDaylightImmutableStyle
25 public abstract class FlowEntity extends AbstractSwitchEntity {
26
27     // This is required as it will cause the code generation by @Immutable.org to implement Builder,
28     // which is required Xtend sources can use the XtendBuilderExtensions.operator_doubleGreaterThan
29     public abstract static class Builder implements org.opendaylight.yangtools.concepts.Builder<FlowEntity> {
30
31     }
32
33     // This was done because MDSALManager has this hard-coded like this, upon MDSALManager.installFlow()
34     @Default
35     public BigInteger getCookie() {
36         return new BigInteger("0110000", 16);
37     }
38
39     public abstract String getFlowId();
40
41     public abstract @Nullable String getFlowName();
42
43     @Default
44     // Confusing to have methods getHardTimeOut() and ActionLearn.getHardTimeout()
45     @SuppressFBWarnings("NM_CONFUSING")
46     public int getHardTimeOut() {
47         return 0;
48     }
49
50     @Default
51     // Confusing to have methods getIdleTimeOut() and ActionLearn.getIdleTimeout()
52     @SuppressFBWarnings("NM_CONFUSING")
53     public int getIdleTimeOut() {
54         return 0;
55     }
56
57     public abstract List<InstructionInfo> getInstructionInfoList();
58
59     public abstract List<MatchInfoBase> getMatchInfoList();
60
61     @Default
62     public int getPriority() {
63         return 0;
64     }
65
66     @Default
67     public boolean getSendFlowRemFlag() {
68         return false;
69     }
70
71     @Default
72     public boolean getStrictFlag() {
73         return false;
74     }
75
76     public abstract short getTableId();
77
78     public FlowBuilder getFlowBuilder() {
79         FlowBuilder flowBuilder = new FlowBuilder();
80
81         flowBuilder.withKey(new FlowKey(new FlowId(getFlowId())));
82
83         flowBuilder.setTableId(getTableId());
84         flowBuilder.setPriority(getPriority());
85         flowBuilder.setFlowName(getFlowName());
86         flowBuilder.setIdleTimeout(getIdleTimeOut());
87         flowBuilder.setHardTimeout(getHardTimeOut());
88         flowBuilder.setCookie(new FlowCookie(getCookie()));
89         flowBuilder.setMatch(MDSALUtil.buildMatches(getMatchInfoList()));
90         flowBuilder.setInstructions(MDSALUtil.buildInstructions(getInstructionInfoList()));
91
92         flowBuilder.setStrict(getStrictFlag());
93         // TODO flowBuilder.setResyncFlag(getResyncFlag());
94         if (getSendFlowRemFlag()) {
95             flowBuilder.setFlags(new FlowModFlags(false, false, false, false, true));
96         }
97
98         flowBuilder.setBarrier(false);
99         flowBuilder.setInstallHw(true);
100
101         return flowBuilder;
102     }
103
104 }