import io.netty.buffer.ByteBuf;\r
import io.netty.buffer.UnpooledByteBufAllocator;\r
\r
+import java.util.ArrayList;\r
import java.util.List;\r
import java.util.Map;\r
import java.util.Map.Entry;\r
\r
import org.opendaylight.openflowjava.protocol.impl.serialization.OFSerializer;\r
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress;\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader;\r
\r
+import com.google.common.base.Joiner;\r
+\r
/** Class for common operations on ByteBuf\r
* @author michal.polkorab\r
* @author timotej.kubas\r
*/\r
public abstract class ByteBufUtils {\r
\r
-\r
/**\r
* Converts ByteBuf into String\r
* @param bb input ByteBuf\r
}\r
return sb.toString();\r
}\r
+ \r
+ /**\r
+ * Converts macAddress to byte array\r
+ * @param macAddress\r
+ * @return byte representation of mac address\r
+ * @see {@link MacAddress}\r
+ */\r
+ public static byte[] macAddressToBytes(String macAddress) {\r
+ String[] sequences = macAddress.split(":");\r
+ byte[] result = new byte[EncodeConstants.MAC_ADDRESS_LENGTH];\r
+ for (int i = 0; i < sequences.length; i++) {\r
+ result[i] = (byte) Short.parseShort(sequences[i], 16);\r
+ }\r
+ return result;\r
+ }\r
+ \r
+ /**\r
+ * Converts mac address represented in bytes to String\r
+ * @param address\r
+ * @return String representation of mac address\r
+ * @see {@link MacAddress}\r
+ */\r
+ public static String macAddressToString(byte[] address) {\r
+ List<String> groups = new ArrayList<>();\r
+ for(int i=0; i < EncodeConstants.MAC_ADDRESS_LENGTH; i++){\r
+ groups.add(String.format("%02X", address[i]));\r
+ }\r
+ Joiner joiner = Joiner.on(":");\r
+ return joiner.join(groups); \r
+ }\r
}\r