address comments
diff --git a/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/DatapathId.java b/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/DatapathId.java
index 2e7a59b..708eaa9 100644
--- a/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/DatapathId.java
+++ b/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/DatapathId.java
@@ -6,7 +6,6 @@
import org.projectfloodlight.openflow.util.HexString;
import com.google.common.hash.PrimitiveSink;
-import com.google.common.primitives.Bytes;
import com.google.common.primitives.Longs;
import com.google.common.primitives.UnsignedLongs;
@@ -40,16 +39,12 @@
}
/**
- * Creates a {@link DatapathId} from a {@link MacAddress}. This factory
- * method assumes that the {@link DatapathId} is composed of two zero bytes
- * appended by the {@link MacAddress}'s 6 bytes.
+ * Creates a {@link DatapathId} from a {@link MacAddress}.
* @param mac the {@link MacAddress} to create the {@link DatapathId} from
* @return a {@link DatapathId} derived from the supplied {@link MacAddress}
*/
public static DatapathId of(@Nonnull MacAddress mac) {
- byte[] zeroBytes = new byte[]{0,0};
- byte[] fullBytes = Bytes.concat(zeroBytes, mac.getBytes());
- return DatapathId.of(fullBytes);
+ return DatapathId.of(mac.getLong());
}
public long getLong() {
diff --git a/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/MacAddress.java b/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/MacAddress.java
index b026b6c..3db7e3a 100644
--- a/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/MacAddress.java
+++ b/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/MacAddress.java
@@ -9,7 +9,6 @@
import org.projectfloodlight.openflow.util.HexString;
import com.google.common.base.Preconditions;
-import com.google.common.base.Strings;
import com.google.common.hash.PrimitiveSink;
import com.google.common.primitives.Longs;
@@ -37,7 +36,7 @@
private static final String FORMAT_ERROR = "Mac address is not well-formed. " +
"It must consist of 6 hex digit pairs separated by colons: ";
- private static final int STRING_LENGTH = 6 * 2 + 5;
+ private static final int MAC_STRING_LENGTH = 6 * 2 + 5;
private MacAddress(final long rawValue) {
this.rawValue = rawValue;
@@ -72,15 +71,18 @@
*/
@Nonnull
public static MacAddress of(@Nonnull final String macString) throws IllegalArgumentException {
- Preconditions.checkArgument(!Strings.isNullOrEmpty(macString),
- "macString must not be null or empty");
- Preconditions.checkArgument(macString.length() == (STRING_LENGTH),
- FORMAT_ERROR + macString);
+ if (macString == null) {
+ throw new NullPointerException("macString must not be null");
+ }
int index = 0;
int shift = 40;
long raw = 0;
+ if (macString.length() != MAC_STRING_LENGTH) {
+ throw new IllegalArgumentException(FORMAT_ERROR + macString);
+ }
+
while (shift >= 0) {
int digit1 = Character.digit(macString.charAt(index++), 16);
int digit2 = Character.digit(macString.charAt(index++), 16);
@@ -99,8 +101,7 @@
/**
* Creates a {@link MacAddress} from a {@link DatapathId}. This factory
- * method assumes that the {@link MacAddress} is composed of the last six
- * bytes of the supplied {@link DatapathId}.
+ * method assumes that the first two bytes of the {@link DatapathId} are 0 bytes.
* @param dpid the {@link DatapathId} to create the {@link MacAddress} from
* @return a {@link MacAddress} derived from the supplied {@link DatapathId}
*/
@@ -108,8 +109,14 @@
Preconditions.checkNotNull(dpid, "dpid must not be null");
byte[] dpidBytes = dpid.getBytes();
- byte[] macBytes = Arrays.copyOfRange(dpidBytes, 2, 8);
- return MacAddress.of(macBytes);
+
+ if (dpidBytes[0] == 0
+ && dpidBytes[1] == 0) {
+ return MacAddress.of(dpid.getLong());
+ } else {
+ throw new IllegalArgumentException("First two bytes of supplied "
+ + "Datapathid must be 0");
+ }
}
private volatile byte[] bytesCache = null;
diff --git a/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/OFBooleanValue.java b/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/OFBooleanValue.java
index a667db6..99416a3 100644
--- a/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/OFBooleanValue.java
+++ b/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/OFBooleanValue.java
@@ -18,6 +18,8 @@
package org.projectfloodlight.openflow.types;
import org.jboss.netty.buffer.ChannelBuffer;
+import org.projectfloodlight.openflow.exceptions.OFParseError;
+import org.projectfloodlight.openflow.protocol.OFMessageReader;
import org.projectfloodlight.openflow.protocol.Writeable;
import com.google.common.hash.PrimitiveSink;
@@ -29,6 +31,8 @@
public final static OFBooleanValue NO_MASK = TRUE;
public final static OFBooleanValue FULL_MASK = FALSE;
+ public final static Reader READER_INSTANCE = new Reader();
+
private final boolean value;
private OFBooleanValue(boolean value) {
@@ -79,6 +83,13 @@
bb.writeByte(getInt());
}
+ private static class Reader implements OFMessageReader<OFBooleanValue> {
+ @Override
+ public OFBooleanValue readFrom(ChannelBuffer bb) throws OFParseError {
+ return of(bb.readByte() != 0);
+ }
+ }
+
@Override
public int getLength() {
return 1;