address comments
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;