2 * Copyright (c) 2008 The Board of Trustees of The Leland Stanford Junior
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
9 * http://www.apache.org/licenses/LICENSE-2.0
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
18 package org.openflow.protocol;
20 import org.jboss.netty.buffer.ChannelBuffer;
21 import org.openflow.util.U16;
22 import org.openflow.protocol.factory.OFVendorDataFactory;
23 import org.openflow.protocol.factory.OFVendorDataFactoryAware;
24 import org.openflow.protocol.vendor.OFVendorData;
27 * Represents ofp_vendor_header
28 * @author David Erickson (daviderickson@cs.stanford.edu)
30 public class OFVendor extends OFMessage implements OFVendorDataFactoryAware {
31 public static int MINIMUM_LENGTH = 12;
34 protected OFVendorData vendorData;
35 protected OFVendorDataFactory vendorDataFactory;
39 this.type = OFType.VENDOR;
40 this.length = U16.t(MINIMUM_LENGTH);
46 public int getVendor() {
51 * @param vendor the vendor to set
53 public void setVendor(int vendor) {
60 public OFVendorData getVendorData() {
65 * @param data the data to set
67 public void setVendorData(OFVendorData vendorData) {
68 this.vendorData = vendorData;
72 public void setVendorDataFactory(OFVendorDataFactory vendorDataFactory) {
73 this.vendorDataFactory = vendorDataFactory;
77 public void readFrom(ChannelBuffer data) {
79 this.vendor = data.readInt();
80 if (vendorDataFactory == null)
81 throw new RuntimeException("OFVendorDataFactory not set");
83 this.vendorData = vendorDataFactory.parseVendorData(vendor,
84 data, super.getLengthU() - MINIMUM_LENGTH);
88 public void writeTo(ChannelBuffer data) {
90 data.writeInt(this.vendor);
91 if (vendorData != null)
92 vendorData.writeTo(data);
96 * @see java.lang.Object#hashCode()
99 public int hashCode() {
100 final int prime = 337;
101 int result = super.hashCode();
102 result = prime * result + vendor;
103 if (vendorData != null)
104 result = prime * result + vendorData.hashCode();
109 * @see java.lang.Object#equals(java.lang.Object)
112 public boolean equals(Object obj) {
115 if (!super.equals(obj))
117 if (getClass() != obj.getClass())
119 OFVendor other = (OFVendor) obj;
120 if (vendor != other.vendor)
122 if (vendorData == null) {
123 if (other.vendorData != null) {
126 } else if (!vendorData.equals(other.vendorData)) {