Remove Serializable from instructions, actions, MatchInfo
[genius.git] / mdsalutil / mdsalutil-api / src / main / java / org / opendaylight / genius / mdsalutil / actions / ActionRegLoad.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 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.openflowjava.nx.match.rev140421.NxmNxReg;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.dst.choice.grouping.dst.choice.DstNxRegCaseBuilder;
17 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;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.nx.action.reg.load.grouping.NxRegLoadBuilder;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.nx.action.reg.load.grouping.nx.reg.load.Dst;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.nx.action.reg.load.grouping.nx.reg.load.DstBuilder;
21
22 /**
23  * Action to load an NXM register.
24  */
25 public class ActionRegLoad extends ActionInfo {
26
27     private final Class<? extends NxmNxReg> register;
28     private final int start;
29     private final int end;
30     private final long load;
31
32     public ActionRegLoad(Class<? extends NxmNxReg> register, int start, int end, long load) {
33         this(0, register, start, end, load);
34     }
35
36     public ActionRegLoad(int actionKey, Class<? extends NxmNxReg> register, int start, int end, long load) {
37         super(actionKey);
38         this.register = register;
39         this.start = start;
40         this.end = end;
41         this.load = load;
42     }
43
44     @Override
45     public Action buildAction() {
46         return buildAction(getActionKey());
47     }
48
49     @Override
50     public Action buildAction(int newActionKey) {
51         Dst dst = new DstBuilder().setDstChoice(new DstNxRegCaseBuilder().setNxReg(register).build())
52                 .setStart(start)
53                 .setEnd(end)
54                 .build();
55         NxRegLoadBuilder nxRegLoadBuilder = new NxRegLoadBuilder().setDst(dst).setValue(BigInteger.valueOf(load));
56
57         return new ActionBuilder()
58                 .setAction(new NxActionRegLoadNodesNodeTableFlowApplyActionsCaseBuilder().setNxRegLoad(
59                         nxRegLoadBuilder.build()).build())
60                 .setKey(new ActionKey(newActionKey))
61                 .build();
62     }
63
64     public Class<? extends NxmNxReg> getRegister() {
65         return register;
66     }
67
68     public int getStart() {
69         return start;
70     }
71
72     public int getEnd() {
73         return end;
74     }
75
76     public long getLoad() {
77         return load;
78     }
79
80     @Override
81     public boolean equals(Object other) {
82         if (this == other) {
83             return true;
84         }
85         if (other == null || getClass() != other.getClass()) {
86             return false;
87         }
88         if (!super.equals(other)) {
89             return false;
90         }
91
92         ActionRegLoad that = (ActionRegLoad) other;
93
94         if (start != that.start) {
95             return false;
96         }
97         if (end != that.end) {
98             return false;
99         }
100         if (load != that.load) {
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         result = 31 * result + (int) (load ^ load >>> 32);
113         return result;
114     }
115
116     @Override
117     public String toString() {
118         return "ActionRegLoad [register=" + register + ", start=" + start + ", end=" + end + ", load=" + load
119                 + ", getActionKey()=" + getActionKey() + "]";
120     }
121
122 }