Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make OFValueType extend the Writeable interface. #505

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,11 @@ public int compareTo(ArpOpcode o) {
return UnsignedInts.compare(opcode, o.opcode);
}

@Override
public void writeTo(ByteBuf bb) {
write2Bytes(bb);
}

@Override
public void putTo(PrimitiveSink sink) {
sink.putShort((short) this.opcode);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@ public int compareTo(BundleId o) {
return UnsignedInts.compare(rawValue, rawValue);
}

@Override
public void writeTo(ByteBuf bb) {
write4Bytes(bb);
}

@Override
public void putTo(PrimitiveSink sink) {
sink.putInt(rawValue);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@ public int compareTo(ClassId o) {
return UnsignedInts.compare(rawValue, rawValue);
}

@Override
public void writeTo(ByteBuf bb) {
write4Bytes(bb);
}

@Override
public void putTo(PrimitiveSink sink) {
sink.putInt(rawValue);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@

import javax.annotation.Nonnull;

import io.netty.buffer.ByteBuf;

import org.projectfloodlight.openflow.annotations.Immutable;
import org.projectfloodlight.openflow.util.HexString;
import org.projectfloodlight.openflow.protocol.Writeable;

import com.google.common.hash.PrimitiveSink;
import com.google.common.primitives.Longs;
Expand All @@ -16,7 +19,7 @@
* @author Rob Vaterlaus {@literal <}[email protected]{@literal >}
*/
@Immutable
public class DatapathId implements PrimitiveSinkable, Comparable<DatapathId> {
public class DatapathId implements Writeable, PrimitiveSinkable, Comparable<DatapathId> {

public static final DatapathId NONE = new DatapathId(0);

Expand Down Expand Up @@ -95,4 +98,9 @@ public void putTo(PrimitiveSink sink) {
public int compareTo(DatapathId o) {
return UnsignedLongs.compare(rawValue, o.rawValue);
}

@Override
public void writeTo(ByteBuf bb) {
bb.writeLong(rawValue);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,11 @@ public int compareTo(EthType o) {
return UnsignedInts.compare(rawValue, o.rawValue);
}

@Override
public void writeTo(ByteBuf bb) {
write2Bytes(bb);
}

@Override
public void putTo(PrimitiveSink sink) {
sink.putInt(rawValue);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@ public int compareTo(GenTableId other) {
return UnsignedInts.compare(this.id, other.id);
}

@Override
public void writeTo(ByteBuf bb) {
write2Bytes(bb);
}

@Override
public void putTo(PrimitiveSink sink) {
sink.putShort((byte) id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@ public int compareTo(ICMPv4Code o) {
return Shorts.compare(code, o.code);
}

@Override
public void writeTo(ByteBuf bb) {
writeByte(bb);
}

@Override
public void putTo(PrimitiveSink sink) {
sink.putShort(code);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,11 @@ public int compareTo(ICMPv4Type o) {
return Shorts.compare(type, o.type);
}

@Override
public void writeTo(ByteBuf bb) {
writeByte(bb);
}

@Override
public void putTo(PrimitiveSink sink) {
sink.putShort(type);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import java.net.Inet6Address;
import java.net.InetAddress;

import io.netty.buffer.ByteBuf;

import javax.annotation.Nonnull;

import com.google.common.base.Preconditions;
Expand Down Expand Up @@ -170,6 +172,9 @@ public abstract IPAddressWithMask<F> withMaskOfLength(
@Override
public abstract int hashCode();

@Override
public abstract void writeTo(ByteBuf bb);

/** parse an IPv4Address or IPv6Address from their conventional string representation.
* For details on supported representations, refer to {@link IPv4Address#of(String)}
* and {@link IPv6Address#of(String)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
*
* @author Andreas Wundsam {@literal <}[email protected]{@literal >}
*/
public class IPv4Address extends IPAddress<IPv4Address> implements Writeable {
public class IPv4Address extends IPAddress<IPv4Address> {
static final int LENGTH = 4;
private final int rawValue;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
*
* @author Andreas Wundsam {@literal <}[email protected]{@literal >}
*/
public class IPv6Address extends IPAddress<IPv6Address> implements Writeable {
public class IPv6Address extends IPAddress<IPv6Address> {
public static final int LENGTH = 16;
private final long raw1;
private final long raw2;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,11 @@ public int compareTo(IPv6FlowLabel o) {
return UnsignedInts.compare(label, o.label);
}

@Override
public void writeTo(ByteBuf bb) {
write4Bytes(bb);
}

@Override
public void putTo(PrimitiveSink sink) {
sink.putInt(this.label);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,11 @@ public byte getDscpValue() {
return dscp;
}

@Override
public void writeTo(ByteBuf bb) {
writeByte(bb);
}

@Override
public void putTo(PrimitiveSink sink) {
sink.putByte(dscp);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ public byte getEcnValue() {
return ecn;
}

@Override
public void writeTo(ByteBuf bb) {
writeByte(bb);
}

@Override
public void putTo(PrimitiveSink sink) {
sink.putByte(ecn);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -656,6 +656,10 @@ public int compareTo(IpProtocol o) {
return Shorts.compare(proto, o.proto);
}

@Override
public void writeTo(ByteBuf bb) {
writeByte(bb);
}

@Override
public void putTo(PrimitiveSink sink) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@ public LagId applyMask(LagId mask) {
return LagId.of(rawValue & mask.rawValue);
}

@Override
public void writeTo(ByteBuf bb) {
write4Bytes(bb);
}

@Override
public void putTo(PrimitiveSink sink) {
sink.putInt(rawValue);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,11 @@ public int compareTo(MacAddress o) {
return Longs.compare(rawValue, o.rawValue);
}

@Override
public void writeTo(ByteBuf bb) {
write6Bytes(bb);
}

@Override
public void putTo(PrimitiveSink sink) {
sink.putLong(rawValue);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import com.google.common.hash.PrimitiveSink;

import io.netty.buffer.ByteBuf;



public class Masked<T extends OFValueType<T>> implements OFValueType<Masked<T>> {
Expand Down Expand Up @@ -89,6 +91,12 @@ public int compareTo(Masked<T> o) {
return mask.compareTo(o.mask);
}

@Override
public void writeTo(ByteBuf bb) {
value.writeTo(bb);
mask.writeTo(bb);
}

@Override
public void putTo(PrimitiveSink sink) {
value.putTo(sink);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,11 @@ public int compareTo(OFBitMask128 o) {
return Long.signum(this.raw2 - o.raw2);
}

@Override
public void writeTo(ByteBuf bb) {
write16Bytes(bb);
}

@Override
public void putTo(PrimitiveSink sink) {
sink.putLong(raw1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,11 @@ public int compareTo(OFBitMask512 o) {
return Long.signum(this.raw8 - o.raw8);
}

@Override
public void writeTo(ByteBuf bb) {
write64Bytes(bb);
}

@Override
public void putTo(PrimitiveSink sink) {
sink.putLong(raw1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

import com.google.common.hash.PrimitiveSink;

public class OFBooleanValue implements Writeable, OFValueType<OFBooleanValue> {
public class OFBooleanValue implements OFValueType<OFBooleanValue> {
public final static OFBooleanValue TRUE = new OFBooleanValue(true);
public final static OFBooleanValue FALSE = new OFBooleanValue(false);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ public int compareTo(OFConnectionIndex o) {
return UnsignedInts.compare(this.connectionIndex,o.connectionIndex);
}

@Override
public void writeTo(ByteBuf bb) {
write4Bytes(bb);
}

@Override
public void putTo(PrimitiveSink sink) {
sink.putInt(connectionIndex);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,11 @@ public int compareTo(OFGroup o) {
return UnsignedInts.compare(this.groupNumber, o.groupNumber);
}

@Override
public void writeTo(ByteBuf bb) {
write4Bytes(bb);
}

@Override
public void putTo(PrimitiveSink sink) {
sink.putInt(groupNumber);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ public int compareTo(OFMetadata o) {
return u64.compareTo(o.u64);
}

@Override
public void writeTo(ByteBuf bb) {
write8Bytes(bb);
}

@Override
public void putTo(PrimitiveSink sink) {
u64.putTo(sink);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,12 @@ public int compareTo(OFPort o) {
return UnsignedInts.compare(this.portNumber, o.portNumber);
}

@Override
public void writeTo(ByteBuf bb) {
// NOTE: May not be the right thing to do for OF1.0!
write4Bytes(bb);
}

@Override
public void putTo(PrimitiveSink sink) {
sink.putInt(portNumber);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package org.projectfloodlight.openflow.types;

import org.projectfloodlight.openflow.protocol.Writeable;



public interface OFValueType<T extends OFValueType<T>> extends Comparable<T>, PrimitiveSinkable {
public interface OFValueType<T extends OFValueType<T>> extends Comparable<T>, Writeable, PrimitiveSinkable {
public int getLength();

public T applyMask(T mask);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,13 @@ public OFVlanVidMatch applyMask(OFVlanVidMatch mask) {
public int compareTo(OFVlanVidMatch o) {
return Shorts.compare(vid, o.vid);
}

@Override
public void writeTo(ByteBuf bb) {
// NOTE: May not be the right thing to do for OF1.0!
write2Bytes(bb);
}

@Override
public void putTo(PrimitiveSink sink) {
sink.putShort(vid);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,13 @@ public int compareTo(PacketType o) {
return UnsignedInts.compare(this.nsType, o.nsType);
}

@Override
public void writeTo(ByteBuf bb) {
// TODO: Change to "write6Bytes(bb)" once Issue #504 is resolved
bb.writeShort(namespace);
bb.writeInt(nsType);
}

@Override
public void putTo(PrimitiveSink sink) {
sink.putInt(namespace);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@ public int compareTo(TableId other) {
return Shorts.compare(this.id, other.id);
}

@Override
public void writeTo(ByteBuf bb) {
writeByte(bb);
}

@Override
public void putTo(PrimitiveSink sink) {
sink.putByte((byte) id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@ public int compareTo(TransportPort o) {
return Ints.compare(port, o.port);
}

@Override
public void writeTo(ByteBuf bb) {
write2Bytes(bb);
}

@Override
public void putTo(PrimitiveSink sink) {
sink.putShort((short) port);
Expand Down
Loading