Ensuring that SET_DL_* action with openflowj only uses OFP_ETH_ALEN
[controller.git] / third-party / openflowj / src / main / java / org / openflow / protocol / action / OFActionDataLayer.java
1 /**
2  * @author David Erickson (daviderickson@cs.stanford.edu) - Mar 11, 2010
3  */
4 package org.openflow.protocol.action;
5
6 import java.nio.ByteBuffer;
7 import java.util.Arrays;
8
9 import org.openflow.protocol.OFPhysicalPort;
10
11 /**
12  * Represents an ofp_action_dl_addr
13  * @author David Erickson (daviderickson@cs.stanford.edu) - Mar 11, 2010
14  */
15 public abstract class OFActionDataLayer extends OFAction {
16     public static int MINIMUM_LENGTH = 16;
17
18     protected byte[] dataLayerAddress;
19
20     /**
21      * @return the dataLayerAddress
22      */
23     public byte[] getDataLayerAddress() {
24         return dataLayerAddress;
25     }
26
27     /**
28      * @param dataLayerAddress the dataLayerAddress to set
29      */
30     public void setDataLayerAddress(byte[] dataLayerAddress) {
31         this.dataLayerAddress = dataLayerAddress;
32     }
33
34     @Override
35     public void readFrom(ByteBuffer data) {
36         super.readFrom(data);
37         if (this.dataLayerAddress == null)
38             this.dataLayerAddress = new byte[OFPhysicalPort.OFP_ETH_ALEN];
39         data.get(this.dataLayerAddress);
40         data.getInt();
41         data.getShort();
42     }
43
44     @Override
45     public void writeTo(ByteBuffer data) {
46         super.writeTo(data);
47         data.put(this.dataLayerAddress, 0, OFPhysicalPort.OFP_ETH_ALEN);
48         data.putInt(0);
49         data.putShort((short) 0);
50     }
51
52     @Override
53     public int hashCode() {
54         final int prime = 347;
55         int result = super.hashCode();
56         result = prime * result + Arrays.hashCode(dataLayerAddress);
57         return result;
58     }
59
60     @Override
61     public boolean equals(Object obj) {
62         if (this == obj) {
63             return true;
64         }
65         if (!super.equals(obj)) {
66             return false;
67         }
68         if (!(obj instanceof OFActionDataLayer)) {
69             return false;
70         }
71         OFActionDataLayer other = (OFActionDataLayer) obj;
72         if (!Arrays.equals(dataLayerAddress, other.dataLayerAddress)) {
73             return false;
74         }
75         return true;
76     }
77 }