Skip to content
Snippets Groups Projects
Commit 3623e1e3 authored by Alex Reimers's avatar Alex Reimers
Browse files

Re-added back in boolean Ethernet.isMACAddress(String macAddress).

parent 51aa40f9
No related branches found
No related tags found
No related merge requests found
......@@ -30,6 +30,7 @@ import org.openflow.util.HexString;
* @author David Erickson (daviderickson@cs.stanford.edu)
*/
public class Ethernet extends BasePacket {
private static String HEXES = "0123456789ABCDEF";
public static final short TYPE_ARP = 0x0806;
public static final short TYPE_IPv4 = 0x0800;
public static final short TYPE_LLDP = (short) 0x88cc;
......@@ -250,11 +251,29 @@ public class Ethernet extends BasePacket {
return this;
}
/**
* Checks to see if a string is a valid MAC address.
* @param macAddress
* @return True if macAddress is a valid MAC, False otherwise
*/
public static boolean isMACAddress(String macAddress) {
String[] macBytes = macAddress.split(":");
if (macBytes.length != 6)
return false;
for (int i = 0; i < 6; ++i) {
if (HEXES.indexOf(macBytes[i].toUpperCase().charAt(0)) == -1 ||
HEXES.indexOf(macBytes[i].toUpperCase().charAt(1)) == -1) {
return false;
}
}
return true;
}
/**
* Accepts a MAC address of the form 00:aa:11:bb:22:cc, case does not
* matter, and returns a corresponding byte[].
* @param macAddress
* @return
* @param macAddress The MAC address to convert into a bye array
* @return The macAddress as a byte array
*/
public static byte[] toMACAddress(String macAddress) {
return MACAddress.valueOf(macAddress).toBytes();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment