Bump version odlparent->6.0.0,mdsal->5.0.3
[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 org.opendaylight.genius.mdsalutil.ActionInfo;
11 import org.opendaylight.genius.mdsalutil.NWUtil;
12 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress;
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionBuilder;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionKey;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.dst.choice.grouping.dst.choice.DstNxArpShaCaseBuilder;
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.DstBuilder;
20 import org.opendaylight.yangtools.yang.common.Empty;
21 import org.opendaylight.yangtools.yang.common.Uint16;
22 import org.opendaylight.yangtools.yang.common.Uint64;
23
24 /**
25  * Load MAC address to SHA (Sender Hardware Address).
26  *
27  * <p>Media address of the sender. In an ARP request this field is used to
28  * indicate the address of the host sending the request. In an ARP reply
29  * this field is used to indicate the address of the host that the request
30  * was looking for.
31  */
32 public class ActionLoadMacToSha extends ActionInfo {
33
34     private final MacAddress address;
35
36     public ActionLoadMacToSha(MacAddress address) {
37         this(0, address);
38     }
39
40     public ActionLoadMacToSha(int actionKey, MacAddress address) {
41         super(actionKey);
42         this.address = address;
43     }
44
45     @Override
46     public Action buildAction() {
47         return buildAction(getActionKey());
48     }
49
50     @Override
51     public Action buildAction(int newActionKey) {
52         return new ActionBuilder()
53             .setAction(new NxActionRegLoadNodesNodeTableFlowApplyActionsCaseBuilder()
54                 .setNxRegLoad(new NxRegLoadBuilder()
55                     .setDst(new DstBuilder()
56                         .setDstChoice(new DstNxArpShaCaseBuilder().setNxArpSha(Empty.getInstance()).build())
57                         .setStart(Uint16.ZERO)
58                         .setEnd(47)
59                         .build())
60                     .setValue(Uint64.valueOf(NWUtil.macToLong(address)))
61                     .build())
62                 .build())
63             .withKey(new ActionKey(newActionKey))
64             .build();
65     }
66
67     public MacAddress getAddress() {
68         return address;
69     }
70
71     @Override
72     public boolean equals(Object other) {
73         if (this == other) {
74             return true;
75         }
76         if (other == null || getClass() != other.getClass()) {
77             return false;
78         }
79         if (!super.equals(other)) {
80             return false;
81         }
82
83         ActionLoadMacToSha that = (ActionLoadMacToSha) other;
84
85         return address != null ? address.equals(that.address) : that.address == null;
86     }
87
88     @Override
89     public int hashCode() {
90         int result = super.hashCode();
91         result = 31 * result + (address != null ? address.hashCode() : 0);
92         return result;
93     }
94
95     @Override
96     public String toString() {
97         return "ActionLoadMacToSha [address=" + address + ", getActionKey()=" + getActionKey() + "]";
98     }
99
100 }