Fix ActionNxConntrack.NxNat problems with xtendbeans (with a test)
[genius.git] / mdsalutil / mdsalutil-api / src / main / java / org / opendaylight / genius / mdsalutil / actions / ActionNxLoadMetadata.java
1 /*
2  * Copyright (c) 2017 Red Hat, 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 package org.opendaylight.genius.mdsalutil.actions;
9
10 import java.math.BigInteger;
11 import org.opendaylight.genius.mdsalutil.ActionInfo;
12 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action;
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionBuilder;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionKey;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.dst.choice.grouping.dst.choice.DstOfMetadataCaseBuilder;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.nodes.node.table.flow.instructions.instruction.instruction.apply.actions._case.apply.actions.action.action.NxActionRegLoadNodesNodeTableFlowApplyActionsCaseBuilder;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.nx.action.reg.load.grouping.NxRegLoadBuilder;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.nx.action.reg.load.grouping.nx.reg.load.DstBuilder;
19
20 /**
21  * NX load metadata action.
22  */
23 public class ActionNxLoadMetadata extends ActionInfo {
24
25     private final BigInteger value;
26     private final Integer startBit;
27     private final Integer endBit;
28
29     public ActionNxLoadMetadata(BigInteger value, Integer startBit, Integer endBit) {
30         this(0, value, startBit, endBit);
31     }
32
33     public ActionNxLoadMetadata(int actionKey, BigInteger value, Integer startBit, Integer endBit) {
34         super(actionKey);
35         this.value = value;
36         this.startBit = startBit;
37         this.endBit = endBit;
38     }
39
40     @Override
41     public Action buildAction() {
42         return buildAction(getActionKey());
43     }
44
45     @Override
46     public Action buildAction(int newActionKey) {
47         return new ActionBuilder()
48             .setAction(new NxActionRegLoadNodesNodeTableFlowApplyActionsCaseBuilder()
49                 .setNxRegLoad(new NxRegLoadBuilder()
50                     .setDst(new DstBuilder()
51                         .setDstChoice(new DstOfMetadataCaseBuilder().setOfMetadata(true).build())
52                         .setStart(startBit)
53                         .setEnd(endBit)
54                         .build())
55                     .setValue(value)
56                     .build())
57                 .build())
58             .setKey(new ActionKey(newActionKey))
59             .build();
60     }
61
62     public BigInteger getValue() {
63         return value;
64     }
65
66     public Integer getStartBit() {
67         return startBit;
68     }
69
70     public Integer getEndBit() {
71         return endBit;
72     }
73
74     @Override
75     public int hashCode() {
76         final int prime = 31;
77         int result = super.hashCode();
78         result = prime * result + (endBit == null ? 0 : endBit.hashCode());
79         result = prime * result + (startBit == null ? 0 : startBit.hashCode());
80         result = prime * result + (value == null ? 0 : value.hashCode());
81         return result;
82     }
83
84     @Override
85     public boolean equals(Object obj) {
86         if (this == obj) {
87             return true;
88         }
89         if (!super.equals(obj)) {
90             return false;
91         }
92         if (getClass() != obj.getClass()) {
93             return false;
94         }
95         ActionNxLoadMetadata other = (ActionNxLoadMetadata) obj;
96         if (endBit == null) {
97             if (other.endBit != null) {
98                 return false;
99             }
100         } else if (!endBit.equals(other.endBit)) {
101             return false;
102         }
103         if (startBit == null) {
104             if (other.startBit != null) {
105                 return false;
106             }
107         } else if (!startBit.equals(other.startBit)) {
108             return false;
109         }
110         if (value == null) {
111             if (other.value != null) {
112                 return false;
113             }
114         } else if (!value.equals(other.value)) {
115             return false;
116         }
117         return true;
118     }
119
120     @Override
121     public String toString() {
122         return "ActionNxLoadMetadata [value=" + value + ", startBit=" + startBit + ", endBit=" + endBit
123                 + ", getValue()=" + getValue() + ", getStartBit()=" + getStartBit() + ", getEndBit()=" + getEndBit()
124                 + "]";
125     }
126 }