Merge "Bug 7466 - NPE thrown for interface without lport tag"
[genius.git] / mdsalutil / mdsalutil-api / src / main / java / org / opendaylight / genius / mdsalutil / actions / ActionLoadMacToSha.java
1 /*
2  * Copyright (c) 2016 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.genius.mdsalutil.ActionType;
13 import org.opendaylight.genius.mdsalutil.NWUtil;
14 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionBuilder;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionKey;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.dst.choice.grouping.dst.choice.DstNxArpShaCaseBuilder;
19 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;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.nx.action.reg.load.grouping.NxRegLoadBuilder;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.nx.action.reg.load.grouping.nx.reg.load.DstBuilder;
22
23 /**
24  * Load MAC address to SHA (Sender Hardware Address).
25  * <p>
26  * Media address of the sender. In an ARP request this field is used to
27  * indicate the address of the host sending the request. In an ARP reply
28  * this field is used to indicate the address of the host that the request
29  * was looking for.
30  */
31 public class ActionLoadMacToSha extends ActionInfo {
32     private final MacAddress address;
33
34     public ActionLoadMacToSha(MacAddress address) {
35         this(0, address);
36     }
37
38     public ActionLoadMacToSha(int actionKey, MacAddress address) {
39         super(ActionType.load_mac_to_sha, new String[] {address.getValue()}, actionKey);
40         this.address = address;
41     }
42
43     @Deprecated
44     public ActionLoadMacToSha(ActionInfo actionInfo) {
45         this(actionInfo.getActionKey(), new MacAddress(actionInfo.getActionValues()[0]));
46     }
47
48     @Override
49     public Action buildAction() {
50         return buildAction(getActionKey());
51     }
52
53     public Action buildAction(int newActionKey) {
54         return new ActionBuilder()
55             .setAction(new NxActionRegLoadNodesNodeTableFlowApplyActionsCaseBuilder()
56                 .setNxRegLoad(new NxRegLoadBuilder()
57                     .setDst(new DstBuilder()
58                         .setDstChoice(new DstNxArpShaCaseBuilder().setNxArpSha(true).build())
59                         .setStart(0)
60                         .setEnd(47)
61                         .build())
62                     .setValue(BigInteger.valueOf(NWUtil.macToLong(address)))
63                     .build())
64                 .build())
65             .setKey(new ActionKey(newActionKey))
66             .build();
67     }
68
69     public MacAddress getAddress() {
70         return address;
71     }
72
73     @Override
74     public boolean equals(Object o) {
75         if (this == o) return true;
76         if (o == null || getClass() != o.getClass()) return false;
77         if (!super.equals(o)) return false;
78
79         ActionLoadMacToSha that = (ActionLoadMacToSha) o;
80
81         return address != null ? address.equals(that.address) : that.address == null;
82     }
83
84     @Override
85     public int hashCode() {
86         int result = super.hashCode();
87         result = 31 * result + (address != null ? address.hashCode() : 0);
88         return result;
89     }
90 }