blob: 68327280da6dad4ef3a8dcfae298e4c6038529ba [file] [log] [blame]
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -08001/**
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 */
21package org.openflow.protocol.action;
22
23import java.util.Arrays;
24
25import net.floodlightcontroller.core.web.serializers.ByteArrayMACSerializer;
26
27import org.codehaus.jackson.map.annotate.JsonSerialize;
28import org.jboss.netty.buffer.ChannelBuffer;
29import org.openflow.protocol.OFPhysicalPort;
30
31/**
32 * Represents an ofp_action_dl_addr
33 * @author David Erickson (daviderickson@cs.stanford.edu) - Mar 11, 2010
34 */
35public abstract class OFActionDataLayer extends OFAction {
36 public static int MINIMUM_LENGTH = 16;
37
38 protected byte[] dataLayerAddress;
39
40 /**
41 * @return the dataLayerAddress
42 */
43 @JsonSerialize(using=ByteArrayMACSerializer.class)
44 public byte[] getDataLayerAddress() {
45 return dataLayerAddress;
46 }
47
48 /**
49 * @param dataLayerAddress the dataLayerAddress to set
50 */
51 public void setDataLayerAddress(byte[] dataLayerAddress) {
52 this.dataLayerAddress = dataLayerAddress;
53 }
54
55 @Override
56 public void readFrom(ChannelBuffer data) {
57 super.readFrom(data);
58 if (this.dataLayerAddress == null)
59 this.dataLayerAddress = new byte[OFPhysicalPort.OFP_ETH_ALEN];
60 data.readBytes(this.dataLayerAddress);
61 data.readInt();
62 data.readShort();
63 }
64
65 @Override
66 public void writeTo(ChannelBuffer data) {
67 super.writeTo(data);
68 data.writeBytes(this.dataLayerAddress);
69 data.writeInt(0);
70 data.writeShort((short) 0);
71 }
72
73 @Override
74 public int hashCode() {
75 final int prime = 347;
76 int result = super.hashCode();
77 result = prime * result + Arrays.hashCode(dataLayerAddress);
78 return result;
79 }
80
81 @Override
82 public boolean equals(Object obj) {
83 if (this == obj) {
84 return true;
85 }
86 if (!super.equals(obj)) {
87 return false;
88 }
89 if (!(obj instanceof OFActionDataLayer)) {
90 return false;
91 }
92 OFActionDataLayer other = (OFActionDataLayer) obj;
93 if (!Arrays.equals(dataLayerAddress, other.dataLayerAddress)) {
94 return false;
95 }
96 return true;
97 }
98}