Fix ActionNxConntrack.NxNat problems with xtendbeans (with a test)
[genius.git] / mdsalutil / mdsalutil-api / src / main / java / org / opendaylight / genius / mdsalutil / actions / ActionRegMove.java
1 /*
2  * Copyright © 2016 Red Hat, Inc. and others.
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 org.opendaylight.genius.mdsalutil.ActionInfo;
11 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action;
12 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionBuilder;
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionKey;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.NxmNxReg;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.dst.choice.grouping.dst.choice.DstOfMplsLabelCaseBuilder;
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.NxActionRegMoveNodesNodeTableFlowApplyActionsCaseBuilder;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.nx.action.reg.move.grouping.NxRegMoveBuilder;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.nx.action.reg.move.grouping.nx.reg.move.Dst;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.nx.action.reg.move.grouping.nx.reg.move.DstBuilder;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.nx.action.reg.move.grouping.nx.reg.move.Src;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.nx.action.reg.move.grouping.nx.reg.move.SrcBuilder;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.src.choice.grouping.src.choice.SrcNxRegCaseBuilder;
23
24 /**
25  * Action to move an NXM register.
26  */
27 public class ActionRegMove extends ActionInfo {
28
29     private final Class<? extends NxmNxReg> register;
30     private final int start;
31     private final int end;
32
33     public ActionRegMove(Class<? extends NxmNxReg> register, int start, int end) {
34         this(0, register, start, end);
35     }
36
37     public ActionRegMove(int actionKey, Class<? extends NxmNxReg> register, int start, int end) {
38         super(actionKey);
39         this.register = register;
40         this.start = start;
41         this.end = end;
42     }
43
44     @Override
45     public Action buildAction() {
46         return buildAction(getActionKey());
47     }
48
49     @Override
50     public Action buildAction(int newActionKey) {
51         Src src = new SrcBuilder()
52                 .setSrcChoice(new SrcNxRegCaseBuilder().setNxReg(register).build())
53                 .setStart(start)
54                 .setEnd(end)
55                 .build();
56
57         Dst dst = new DstBuilder()
58                 .setDstChoice(new DstOfMplsLabelCaseBuilder().setOfMplsLabel(true).build())
59                 .setStart(start)
60                 .setEnd(end)
61                 .build();
62
63         NxRegMoveBuilder nxRegMoveBuilder = new NxRegMoveBuilder().setSrc(src).setDst(dst);
64         return new ActionBuilder()
65                 .setAction(new NxActionRegMoveNodesNodeTableFlowApplyActionsCaseBuilder().setNxRegMove(
66                         nxRegMoveBuilder.build()).build())
67                 .setKey(new ActionKey(newActionKey))
68                 .build();
69     }
70
71     public Class<? extends NxmNxReg> getRegister() {
72         return register;
73     }
74
75     public int getStart() {
76         return start;
77     }
78
79     public int getEnd() {
80         return end;
81     }
82
83     @Override
84     public boolean equals(Object other) {
85         if (this == other) {
86             return true;
87         }
88         if (other == null || getClass() != other.getClass()) {
89             return false;
90         }
91         if (!super.equals(other)) {
92             return false;
93         }
94
95         ActionRegMove that = (ActionRegMove) other;
96
97         if (start != that.start) {
98             return false;
99         }
100         if (end != that.end) {
101             return false;
102         }
103         return register != null ? register.equals(that.register) : that.register == null;
104     }
105
106     @Override
107     public int hashCode() {
108         int result = super.hashCode();
109         result = 31 * result + (register != null ? register.hashCode() : 0);
110         result = 31 * result + start;
111         result = 31 * result + end;
112         return result;
113     }
114
115     @Override
116     public String toString() {
117         return "ActionRegMove [register=" + register + ", start=" + start + ", end=" + end + ", getActionKey()="
118                 + getActionKey() + "]";
119     }
120
121 }