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