a6eae63e240dc9e435a237b8148688bcae625512
[openflowjava.git] / third-party / openflowj_netty / src / main / java / org / openflow / protocol / action / OFActionDataLayer.java
1 /**
2 *    Copyright (c) 2008 The Board of Trustees of The Leland Stanford Junior
3 *    University
4
5 *    Licensed under the Apache License, Version 2.0 (the "License"); you may
6 *    not use this file except in compliance with the License. You may obtain
7 *    a copy of the License at
8 *
9 *         http://www.apache.org/licenses/LICENSE-2.0
10 *
11 *    Unless required by applicable law or agreed to in writing, software
12 *    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13 *    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14 *    License for the specific language governing permissions and limitations
15 *    under the License.
16 **/
17
18 /**
19  * @author David Erickson (daviderickson@cs.stanford.edu) - Mar 11, 2010
20  */
21 package org.openflow.protocol.action;
22
23 import java.util.Arrays;
24
25
26
27 import org.jboss.netty.buffer.ChannelBuffer;
28 import org.openflow.protocol.OFPhysicalPort;
29
30 /**
31  * Represents an ofp_action_dl_addr
32  * @author David Erickson (daviderickson@cs.stanford.edu) - Mar 11, 2010
33  */
34 public abstract class OFActionDataLayer extends OFAction {
35     public static int MINIMUM_LENGTH = 16;
36
37     protected byte[] dataLayerAddress;
38
39     /**
40      * @return the dataLayerAddress
41      */
42     public byte[] getDataLayerAddress() {
43         return dataLayerAddress;
44     }
45
46     /**
47      * @param dataLayerAddress the dataLayerAddress to set
48      */
49     public void setDataLayerAddress(byte[] dataLayerAddress) {
50         this.dataLayerAddress = dataLayerAddress;
51     }
52
53     @Override
54     public void readFrom(ChannelBuffer data) {
55         super.readFrom(data);
56         if (this.dataLayerAddress == null)
57             this.dataLayerAddress = new byte[OFPhysicalPort.OFP_ETH_ALEN];
58         data.readBytes(this.dataLayerAddress);
59         data.readInt();
60         data.readShort();
61     }
62
63     @Override
64     public void writeTo(ChannelBuffer data) {
65         super.writeTo(data);
66         data.writeBytes(this.dataLayerAddress);
67         data.writeInt(0);
68         data.writeShort((short) 0);
69     }
70
71     @Override
72     public int hashCode() {
73         final int prime = 347;
74         int result = super.hashCode();
75         result = prime * result + Arrays.hashCode(dataLayerAddress);
76         return result;
77     }
78
79     @Override
80     public boolean equals(Object obj) {
81         if (this == obj) {
82             return true;
83         }
84         if (!super.equals(obj)) {
85             return false;
86         }
87         if (!(obj instanceof OFActionDataLayer)) {
88             return false;
89         }
90         OFActionDataLayer other = (OFActionDataLayer) obj;
91         if (!Arrays.equals(dataLayerAddress, other.dataLayerAddress)) {
92             return false;
93         }
94         return true;
95     }
96 }