* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
-
package org.opendaylight.openflowjava.util;
import com.google.common.base.Preconditions;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader;
-/** Class for common operations on ByteBuf
+/**
+ * Class for common operations on ByteBuf.
+ *
* @author michal.polkorab
* @author timotej.kubas
*/
}
/**
- * Converts ByteBuf into String
+ * Converts ByteBuf into String.
+ *
* @param bb input ByteBuf
* @return String
*/
public static String byteBufToHexString(final ByteBuf bb) {
StringBuilder sb = new StringBuilder();
- for (int i = bb.readerIndex(); i < (bb.readerIndex() + bb.readableBytes()); i++) {
+ for (int i = bb.readerIndex(); i < bb.readerIndex() + bb.readableBytes(); i++) {
sb.append(String.format(" %02x", bb.getUnsignedByte(i)));
}
return sb.toString().trim();
}
/**
- * Converts String into byte[]
+ * Converts String into byte[].
+ *
* @param hexSrc input String
* @return byte[] filled with input data
*/
}
/**
- * Converts String into byte[]
+ * Converts String into byte[].
+ *
* @param hexSrc input String
* @param withSpaces if there are spaces in string
* @return byte[] filled with input data
final Splitter splitter = withSpaces ? HEXSTRING_SPLITTER : HEXSTRING_NOSPACE_SPLITTER;
List<String> byteChips = Lists.newArrayList(splitter.split(hexSrc));
byte[] result = new byte[byteChips.size()];
- int i = 0;
+ int index = 0;
for (String chip : byteChips) {
- result[i] = (byte) Short.parseShort(chip, 16);
- i++;
+ result[index] = (byte) Short.parseShort(chip, 16);
+ index++;
}
return result;
}
/**
- * Creates ByteBuf filled with specified data
+ * Creates ByteBuf filled with specified data.
+ *
* @param hexSrc input String of bytes in hex format
* @return ByteBuf with specified hexString converted
*/
}
/**
- * Creates ByteBuf filled with specified data
+ * Creates ByteBuf filled with specified data.
+ *
* @param hexSrc input String of bytes in hex format
* @param out ByteBuf with specified hexString converted
*/
}
/**
- * Fills specified ByteBuf with 0 (zeros) of desired length, used for padding
- * @param length
+ * Fills specified ByteBuf with 0 (zeros) of desired length, used for padding.
+ *
+ * @param length the desired length
* @param out ByteBuf to be padded
* @deprecated Use {@link ByteBuf#writeZero(int)} directly.
*/
}
/**
- * Create standard OF header
+ * Create standard OF header.
+ *
* @param msgType message code
* @param message POJO
* @param out writing buffer
* @param length ofheader length
*/
- public static <E extends OfHeader> void writeOFHeader(final byte msgType, final E message, final ByteBuf out, final int length) {
+ public static <E extends OfHeader> void writeOFHeader(final byte msgType, final E message, final ByteBuf out,
+ final int length) {
out.writeByte(message.getVersion());
out.writeByte(msgType);
out.writeShort(length);
}
/**
- * Write length standard OF header
+ * Write length standard OF header.
+ *
* @param out writing buffer
*/
public static void updateOFHeaderLength(final ByteBuf out) {
}
/**
- * Write length OF header
+ * Write length OF header.
+ *
* @param out writing buffer
* @param index writing index
*/
}
/**
- * Fills the bitmask from boolean map where key is bit position
+ * Fills the bitmask from boolean map where key is bit position.
+ *
* @param booleanMap bit to boolean mapping
* @return bit mask
*/
public static int fillBitMask(final int offset, final boolean... values) {
int bitmask = 0;
- int i = offset;
+ int index = offset;
for (boolean v : values) {
if (v) {
- bitmask |= 1 << i;
+ bitmask |= 1 << index;
}
- ++i;
+ ++index;
}
return bitmask;
}
/**
- * Fills the bitmask from boolean list where key is bit position
+ * Fills the bitmask from boolean list where key is bit position.
+ *
* @param booleanList bit to boolean mapping
* @return bit mask
*/
int[] bitmask;
int index = 0;
int arrayIndex = 0;
- if ((booleanList.size() % Integer.SIZE) != 0) {
+ if (booleanList.size() % Integer.SIZE != 0) {
bitmask = new int[booleanList.size() / Integer.SIZE + 1];
} else {
bitmask = new int[booleanList.size() / Integer.SIZE];
}
/**
- * Converts byte array into String
+ * Converts byte array into String.
+ *
* @param array input byte array
* @return String
*/
return sb.toString().trim();
}
- private static int hexValue(final char c) {
- if (c >= '0' && c <= '9') {
- return c - '0';
+ private static int hexValue(final char ch) {
+ if (ch >= '0' && ch <= '9') {
+ return ch - '0';
}
- if (c >= 'a' && c <= 'f') {
- return c - 'a' + 10;
+ if (ch >= 'a' && ch <= 'f') {
+ return ch - 'a' + 10;
}
- if (c >= 'A' && c <= 'F') {
- return c - 'A' + 10;
+ if (ch >= 'A' && ch <= 'F') {
+ return ch - 'A' + 10;
}
- throw new IllegalArgumentException(String.format("Invalid character '%s' encountered", c));
+ throw new IllegalArgumentException(String.format("Invalid character '%s' encountered", ch));
}
/**
* Converts macAddress to byte array.
* See also {@link org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress}.
*
- * @param macAddress
+ * @param macAddress the mac address to convert
* @return byte representation of mac address
*/
+ @SuppressWarnings("checkstyle:IllegalCatch")
public static byte[] macAddressToBytes(final String macAddress) {
final byte[] result = new byte[EncodeConstants.MAC_ADDRESS_LENGTH];
final char[] mac = macAddress.toCharArray();
offset++;
} else {
result[i] = UnsignedBytes.checkedCast(
- (hexValue(mac[offset]) << 4) | hexValue(mac[offset +1]));
+ hexValue(mac[offset]) << 4 | hexValue(mac[offset + 1]));
offset += 2;
}
Preconditions.checkArgument(mac[offset] == ':', "Invalid value: %s", macAddress);
offset++;
}
- if (offset == (mac.length - 1)) {
+ if (offset == mac.length - 1) {
result[EncodeConstants.MAC_ADDRESS_LENGTH - 1] = UnsignedBytes.checkedCast(hexValue(mac[offset]));
} else {
result[EncodeConstants.MAC_ADDRESS_LENGTH - 1] =
- UnsignedBytes.checkedCast(hexValue(mac[offset]) << 4 | hexValue(mac[offset +1]));
+ UnsignedBytes.checkedCast(hexValue(mac[offset]) << 4 | hexValue(mac[offset + 1]));
offset++;
}
- if (offset != (mac.length -1)) {
+ if (offset != mac.length - 1) {
throw new IllegalArgumentException("Incorrect MAC address length");
}
- } catch (Exception e) {
+ } catch (RuntimeException e) {
throw new IllegalArgumentException("Unable to serialize MAC address for input: " + macAddress
+ ". \n" + e);
}
return result;
}
- private static final void appendHexByte(final StringBuilder sb, final byte b) {
- final int v = UnsignedBytes.toInt(b);
+ private static void appendHexByte(final StringBuilder sb, final byte value) {
+ final int v = UnsignedBytes.toInt(value);
sb.append(HEX_CHARS[v >>> 4]);
sb.append(HEX_CHARS[v & 15]);
}
private static void appendHexUnsignedShort(final StringBuilder sb, final int val) {
- sb.append(ByteBufUtils.HEX_CHARS[(val >>> 12) & 15]);
- sb.append(ByteBufUtils.HEX_CHARS[(val >>> 8) & 15]);
- sb.append(ByteBufUtils.HEX_CHARS[(val >>> 4) & 15]);
+ sb.append(ByteBufUtils.HEX_CHARS[val >>> 12 & 15]);
+ sb.append(ByteBufUtils.HEX_CHARS[val >>> 8 & 15]);
+ sb.append(ByteBufUtils.HEX_CHARS[val >>> 4 & 15]);
sb.append(ByteBufUtils.HEX_CHARS[ val & 15]);
}
* Converts a MAC address represented in bytes to String.
* See also {@link org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress}.
*
- * @param address
+ * @param address the MAC address to convert
* @return String representation of a MAC address
*/
public static String macAddressToString(final byte[] address) {
}
/**
- * Reads and parses null-terminated string from ByteBuf
- * @param rawMessage
+ * Reads and parses null-terminated string from ByteBuf.
+ *
+ * @param rawMessage the message to parse
* @param length maximal length of String
* @return String with name of port
*/
return IetfYangUtil.INSTANCE.macAddressFor(tmp);
}
- public static byte[] serializeList(final List<Short> list) throws IOException{
+ public static byte[] serializeList(final List<Short> list) throws IOException {
ByteBuffer byteBuffer = ByteBuffer.allocate(list.size() * 2);
- for (Short aShort : list) {
- byteBuffer.putShort(aShort);
+ for (Short shortValue : list) {
+ byteBuffer.putShort(shortValue);
}
return byteBuffer.array();
}
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.table.features.properties.grouping.TableFeatureProperties;
/**
+ * Factory for creating experimenter deserializer keys.
+ *
* @author michal.polkorab
*/
-public abstract class ExperimenterDeserializerKeyFactory {
+public final class ExperimenterDeserializerKeyFactory {
private ExperimenterDeserializerKeyFactory() {
//not called
}
/**
+ * Creates an experimenter error deserializer key.
+ *
* @param version openflow wire version
* @param experimenterId experimenter / vendor ID
* @return key instance
}
/**
+ * Creates an experimenter message deserializer key.
+ *
* @param version openflow wire version
* @param experimenterId experimenter / vendor ID
* @param type experimenter type according to vendor implementation
}
/**
- * @param version openflow wire version
+ * Creates a vendor message deserializer key.
+ *
+ * @param version openflow wire version
* @param experimenterId experimenter / vendor ID
* @return key instance
*/
}
/**
+ * Creates a multi-part reply message deserializer key.
+ *
* @param version openflow wire version
* @param experimenterId experimenter / vendor ID
- * @param type
+ * @param type the type
* @return key instance
*/
public static ExperimenterIdTypeDeserializerKey createMultipartReplyMessageDeserializerKey(
}
/**
- * @param version openflow wire version
+ * Creates a multi-part reply vendor message deserializer key.
+ *
+ * @param version openflow wire version
* @param experimenterId experimenter / vendor ID
* @return key instance
*/
}
/**
+ * Creates a multi-part reply TF deserializer key.
+ *
* @param version openflow wire version
* @param experimenterId experimenter / vendor ID
* @return key instance
}
/**
+ * Creates a queue property deserializer key.
+ *
* @param version openflow wire version
* @param experimenterId experimenter / vendor ID
* @return key instance
}
/**
+ * Creates a meter band deserializer key.
+ *
* @param version openflow wire version
* @param experimenterId experimenter / vendor ID
* @return key instance
short version, Long experimenterId) {
return new ExperimenterIdDeserializerKey(version, experimenterId, MeterBandExperimenterCase.class);
}
-
-}
\ No newline at end of file
+}
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.table.features.properties.grouping.TableFeatureProperties;
/**
+ * Factory for creating experimenter serializer keys.
+ *
* @author michal.polkorab
*/
public abstract class ExperimenterSerializerKeyFactory {
/**
+ * Creates an experimenter message serializer key.
+ *
* @param msgVersion openflow wire version
* @param experimenterId experimenter / vendor ID
* @param type experimenter type according to vendor implementation
}
/**
+ * Creates a multi-part request serializer key.
+ *
* @param msgVersion openflow wire version
* @param experimenterId experimenter / vendor ID
* @param type experimenter type according to vendor implementation
}
/**
+ * Creates a multi-part request TF serializer key.
+ *
* @param msgVersion openflow wire version
* @param experimenterId experimenter / vendor ID
* @return key instance
}
/**
+ * Creates a meter band serializer key.
+ *
* @param msgVersion openflow wire version
* @param experimenterId experimenter / vendor ID
* @return key instance
*/
public static ExperimenterIdSerializerKey<MeterBandExperimenterCase> createMeterBandSerializerKey(
short msgVersion, long experimenterId) {
- return new ExperimenterIdMeterSubTypeSerializerKey<>(msgVersion, experimenterId, MeterBandExperimenterCase.class, null);
+ return new ExperimenterIdMeterSubTypeSerializerKey<>(msgVersion, experimenterId,
+ MeterBandExperimenterCase.class, null);
}
public static ExperimenterIdSerializerKey<MeterBandExperimenterCase> createMeterBandSerializerKey(
short msgVersion, long experimenterId, Class<? extends ExperimenterMeterBandSubType> meterSubType) {
- return new ExperimenterIdMeterSubTypeSerializerKey<>(msgVersion, experimenterId, MeterBandExperimenterCase.class, meterSubType);
+ return new ExperimenterIdMeterSubTypeSerializerKey<>(msgVersion, experimenterId,
+ MeterBandExperimenterCase.class, meterSubType);
}
-
-}
\ No newline at end of file
+}
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.HelloInputBuilder;
/**
- * @author michal.polkorab
+ * Unit tests for ByteBufUtils.
*
+ * @author michal.polkorab
*/
public class ByteBufUtilsTest {
- private final byte[] EXPECTED = new byte[]{0x01, 0x02, 0x03, 0x04, 0x05, (byte) 0xff};
- private final byte[] EXPECTEDVALUES1AND255 = new byte[]{0x00, 0x01, 0x00, (byte) 0xff};
+ private static final byte[] EXPECTED = new byte[]{0x01, 0x02, 0x03, 0x04, 0x05, (byte) 0xff};
+ private static final byte[] EXPECTEDVALUES1AND255 = new byte[]{0x00, 0x01, 0x00, (byte) 0xff};
/**
- * Test of {@link org.opendaylight.openflowjava.util.ByteBufUtils#hexStringToBytes(String)}
+ * Test of {@link org.opendaylight.openflowjava.util.ByteBufUtils#hexStringToBytes(String)}.
*/
@Test
public void testHexStringToBytes() {
}
/**
- * Test of {@link ByteBufUtils#hexStringToBytes(String, boolean)}
+ * Test of {@link ByteBufUtils#hexStringToBytes(String, boolean)}.
*/
@Test
public void testHexStringToBytes2() {
}
/**
- * Test of {@link ByteBufUtils#hexStringToByteBuf(String)}
+ * Test of {@link ByteBufUtils#hexStringToByteBuf(String)}.
*/
@Test
public void testHexStringToByteBuf() {
}
/**
- * Test of {@link ByteBufUtils#hexStringToByteBuf(String, ByteBuf)}
+ * Test of {@link ByteBufUtils#hexStringToByteBuf(String, ByteBuf)}.
*/
@Test
public void testHexStringToGivenByteBuf() {
}
/**
- * Test of {@link ByteBufUtils#fillBitMaskFromMap(java.util.Map)}
+ * Test of {@link ByteBufUtils#fillBitMaskFromMap(java.util.Map)}.
*/
@Test
public void testFillBitmaskByEmptyMap() {
private static String toBinaryString(Map<Integer, Boolean> emptyMap, int length) {
String binaryString = Integer.toBinaryString(ByteBufUtils.fillBitMaskFromMap(emptyMap));
- return String.format("%"+length+"s", binaryString).replaceAll(" ", "0");
+ return String.format("%" + length + "s", binaryString).replaceAll(" ", "0");
}
/**
- * Test of {@link ByteBufUtils#fillBitMaskFromMap(java.util.Map)}
+ * Test of {@link ByteBufUtils#fillBitMaskFromMap(java.util.Map)}.
*/
@Test
public void testFillBitmaskByFullMap() {
Map<Integer, Boolean> fullMap = new HashMap<>();
String expectedBinaryString = "11111111111111111111111111111111";
String bitmaskValueInBinarySytring;
- for(Integer i=0;i<=31;i++) {
+ for (Integer i = 0; i <= 31; i++) {
fullMap.put(i, true);
}
bitmaskValueInBinarySytring = toBinaryString(fullMap, 32);
}
/**
- * Test of {@link ByteBufUtils#fillBitMaskFromMap(java.util.Map)}
+ * Test of {@link ByteBufUtils#fillBitMaskFromMap(java.util.Map)}.
*/
@Test
public void testFillBitmaskByZeroMap() {
Map<Integer, Boolean> zeroMap = new HashMap<>();
String expectedBinaryString = "00000000000000000000000000000000";
String bitmaskValueInBinarySytring;
- for(Integer i=0;i<=31;i++) {
+ for (Integer i = 0; i <= 31; i++) {
zeroMap.put(i, false);
}
bitmaskValueInBinarySytring = toBinaryString(zeroMap, 32);
}
/**
- * Test of {@link ByteBufUtils#fillBitMaskFromMap(java.util.Map)}
+ * Test of {@link ByteBufUtils#fillBitMaskFromMap(java.util.Map)}.
*/
@Test
public void testFillBitmaskByRandomSet() {
String expectedBinaryString = "00000000000000000111100000000000";
String bitmaskValueInBinarySytring;
Boolean mapValue;
- for(Integer i=0;i<=31;i++) {
+ for (Integer i = 0; i <= 31; i++) {
mapValue = false;
- if(i>=11 && i<=14) {
+ if (i >= 11 && i <= 14) {
mapValue = true;
}
randomMap.put(i, mapValue);
}
/**
- * Test of {@link ByteBufUtils#fillBitMaskFromList(List)}
+ * Test of {@link ByteBufUtils#fillBitMaskFromList(List)}.
*/
@Test
public void testFillBitmaskByEmptyList() {
int[] bitMaskArray;
bitMaskArray = ByteBufUtils.fillBitMaskFromList(emptyList);
String binaryString = Integer.toBinaryString(bitMaskArray[0]);
- return String.format("%"+length+"s", binaryString).replaceAll(" ", "0");
+ return String.format("%" + length + "s", binaryString).replaceAll(" ", "0");
}
/**
- * Test of {@link ByteBufUtils#fillBitMaskFromList(List)}
+ * Test of {@link ByteBufUtils#fillBitMaskFromList(List)}.
*/
@Test
public void testFillBitmaskByFullList() {
List<Boolean> fullList = new ArrayList<>();
String expectedBinaryString = "11111111111111111111111111111111";
String bitmaskValueInBinarySytring;
- for(Integer i=0;i<=31;i++) {
+ for (Integer i = 0; i <= 31; i++) {
fullList.add(true);
}
bitmaskValueInBinarySytring = listToBinaryString(fullList, 32);
}
/**
- * Test of {@link ByteBufUtils#fillBitMaskFromList(List)}
+ * Test of {@link ByteBufUtils#fillBitMaskFromList(List)}.
*/
@Test
public void testFillBitmaskByZeroList() {
List<Boolean> zeroList = new ArrayList<>();
String expectedBinaryString = "00000000000000000000000000000000";
String bitmaskValueInBinarySytring;
- for(Integer i=0;i<=31;i++) {
+ for (Integer i = 0; i <= 31; i++) {
zeroList.add(false);
}
bitmaskValueInBinarySytring = listToBinaryString(zeroList, 32);
}
/**
- * Test of {@link ByteBufUtils#fillBitMaskFromList(List)}
+ * Test of {@link ByteBufUtils#fillBitMaskFromList(List)}.
*/
@Test
public void testFillBitmaskFromRandomList() {
String expectedBinaryString = "00000000000000000111100000000000";
String bitmaskValueInBinarySytring;
Boolean listValue;
- for(Integer i=0;i<=31;i++) {
+ for (Integer i = 0; i <= 31; i++) {
listValue = false;
- if(i>=11 && i<=14) {
+ if (i >= 11 && i <= 14) {
listValue = true;
}
randomList.add(listValue);
}
/**
- * Test of {@link ByteBufUtils#macAddressToBytes(String)}
+ * Test of {@link ByteBufUtils#macAddressToBytes(String)}.
*/
@Test
public void testMacToBytes() {
}
/**
- * Test of {@link ByteBufUtils#macAddressToBytes(String)}
+ * Test of {@link ByteBufUtils#macAddressToBytes(String)}.
*/
- @Test(expected=IllegalArgumentException.class)
+ @Test(expected = IllegalArgumentException.class)
public void testMacToBytes2() {
Assert.assertArrayEquals("Wrong byte array", new byte[]{0, 1, 2, 3, (byte) 255, 5},
ByteBufUtils.macAddressToBytes("00:01:02:03:FF:0G"));
}
/**
- * Test of {@link ByteBufUtils#macAddressToBytes(String)}
+ * Test of {@link ByteBufUtils#macAddressToBytes(String)}.
*/
- @Test(expected=IllegalArgumentException.class)
+ @Test(expected = IllegalArgumentException.class)
public void testMacToBytesTooShort() {
ByteBufUtils.macAddressToBytes("00:01:02:03:FF");
}
/**
- * Test of {@link ByteBufUtils#macAddressToBytes(String)}
+ * Test of {@link ByteBufUtils#macAddressToBytes(String)}.
*/
- @Test(expected=IllegalArgumentException.class)
+ @Test(expected = IllegalArgumentException.class)
public void testMacToBytesTooShort2() {
ByteBufUtils.macAddressToBytes("00:01:02:03:FF:");
}
/**
- * Test of {@link ByteBufUtils#macAddressToBytes(String)}
+ * Test of {@link ByteBufUtils#macAddressToBytes(String)}.
*/
- @Test(expected=IllegalArgumentException.class)
+ @Test(expected = IllegalArgumentException.class)
public void testIncorrectMacToBytes() {
ByteBufUtils.macAddressToBytes("00:01:02:03:FF::");
}
/**
- * Test of {@link ByteBufUtils#macAddressToBytes(String)}
+ * Test of {@link ByteBufUtils#macAddressToBytes(String)}.
*/
- @Test(expected=IllegalArgumentException.class)
+ @Test(expected = IllegalArgumentException.class)
public void testIncorrectMacToBytes2() {
ByteBufUtils.macAddressToBytes("00:01:02:03:FF:::");
}
/**
- * Test of {@link ByteBufUtils#macAddressToBytes(String)}
+ * Test of {@link ByteBufUtils#macAddressToBytes(String)}.
*/
- @Test(expected=IllegalArgumentException.class)
+ @Test(expected = IllegalArgumentException.class)
public void testMacToBytesTooLong() {
ByteBufUtils.macAddressToBytes("00:01:02:03:FF:05:85");
}
/**
- * Test of {@link ByteBufUtils#macAddressToBytes(String)}
+ * Test of {@link ByteBufUtils#macAddressToBytes(String)}.
*/
- @Test(expected=IllegalArgumentException.class)
+ @Test(expected = IllegalArgumentException.class)
public void testMacToBytesInvalidOctet() {
ByteBufUtils.macAddressToBytes("00:01:02:03:FF:05d");
}
/**
- * Test of {@link ByteBufUtils#macAddressToBytes(String)}
+ * Test of {@link ByteBufUtils#macAddressToBytes(String)}.
*/
- @Test(expected=IllegalArgumentException.class)
+ @Test(expected = IllegalArgumentException.class)
public void testMacToBytesInvalidOctet2() {
ByteBufUtils.macAddressToBytes("00:01:rr:03:FF:05");
}
/**
- * Test of {@link ByteBufUtils#macAddressToBytes(String)}
+ * Test of {@link ByteBufUtils#macAddressToBytes(String)}.
*/
- @Test(expected=IllegalArgumentException.class)
+ @Test(expected = IllegalArgumentException.class)
public void testMacToBytesInvalidOctet3() {
ByteBufUtils.macAddressToBytes("00:01:05d:03:FF:02");
}
/**
- * Test of {@link ByteBufUtils#macAddressToString(byte[])}
+ * Test of {@link ByteBufUtils#macAddressToString(byte[])}.
*/
- @Test(expected=IllegalArgumentException.class)
+ @Test(expected = IllegalArgumentException.class)
public void testMacToString() {
Assert.assertEquals("Wrong string decoded", "00:01:02:03:FF:05",
ByteBufUtils.macAddressToString(new byte[]{0, 1, 2, 3, (byte) 255, 5}));
}
/**
- * Test of {@link ByteBufUtils#decodeNullTerminatedString(ByteBuf, int)}
+ * Test of {@link ByteBufUtils#decodeNullTerminatedString(ByteBuf, int)}.
*/
@Test
public void testDecodeString() {
}
/**
- * Test of {@link ByteBufUtils#byteBufToHexString(ByteBuf)}
+ * Test of {@link ByteBufUtils#byteBufToHexString(ByteBuf)}.
*/
@Test
public void testByteBufToHexString() {
}
/**
- * Buffer padding test
+ * Buffer padding test.
*/
@Test
public void testPadBuffer() {
}
/**
- * Write OF header test
+ * Write OF header test.
*/
@Test
public void testWriteHeader() {
- ByteBuf buf = PooledByteBufAllocator.DEFAULT.buffer();
HelloInputBuilder helloBuilder = new HelloInputBuilder();
helloBuilder.setVersion((short) EncodeConstants.OF13_VERSION_ID);
helloBuilder.setXid(12345L);
helloBuilder.setElements(null);
HelloInput helloInput = helloBuilder.build();
+ ByteBuf buf = PooledByteBufAllocator.DEFAULT.buffer();
ByteBufUtils.writeOFHeader((byte) 0, helloInput, buf, EncodeConstants.OFHEADER_SIZE);
Assert.assertEquals("Wrong version", EncodeConstants.OF13_VERSION_ID, buf.readUnsignedByte());
Assert.assertEquals("Wrong type", 0, buf.readUnsignedByte());
}
/**
- * Fill bitmask test
+ * Fill bitmask test.
*/
@Test
public void testFillBitmask() {
}
/**
- * Test bytes to hex string
+ * Test bytes to hex string.
*/
@Test
public void testBytesToHexString() {
}
/**
- * Test ipv4 address conversion
+ * Test ipv4 address conversion.
*/
- @Test(expected=IndexOutOfBoundsException.class)
+ @Test(expected = IndexOutOfBoundsException.class)
public void testReadIpv4Address() {
ByteBuf buffer = PooledByteBufAllocator.DEFAULT.buffer();
buffer.writeByte(10);
}
/**
- * Test ipv6 address conversion
+ * Test ipv6 address conversion.
*/
- @Test(expected=IndexOutOfBoundsException.class)
+ @Test(expected = IndexOutOfBoundsException.class)
public void testReadIpv6Address() {
ByteBuf buffer = PooledByteBufAllocator.DEFAULT.buffer();
buffer.writeShort(10);
shorts.add((short) 255);
final byte[] bytes = ByteBufUtils.serializeList(shorts);
- Assert.assertTrue(bytes.length == shorts.size()*2);
+ Assert.assertTrue(bytes.length == shorts.size() * 2);
Assert.assertArrayEquals(EXPECTEDVALUES1AND255, bytes);
}
public void testUpdateHeader() throws IOException {
ByteBuf buffer = PooledByteBufAllocator.DEFAULT.buffer();
buffer.writeInt(1);
- int start = buffer.writerIndex();
+ final int start = buffer.writerIndex();
buffer.writeShort(4);
buffer.writeShort(EncodeConstants.EMPTY_LENGTH);
buffer.writeLong(8);
- int end = buffer.writerIndex();
+ final int end = buffer.writerIndex();
ByteBufUtils.updateOFHeaderLength(buffer, start);
Assert.assertEquals(buffer.readInt(), 1);
Assert.assertEquals(buffer.readShort(), 4);
Assert.assertEquals(buffer.readShort(), 12);
- Assert.assertEquals(buffer.readLong(), 8l);
+ Assert.assertEquals(buffer.readLong(), 8L);
Assert.assertEquals(buffer.getShort(start + EncodeConstants.OFHEADER_LENGTH_INDEX), end - start);
}
}
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.table.features.properties.grouping.TableFeatureProperties;
/**
+ * Unit tests for ExperimenterDeserializerKeyFactory.
+ *
* @author michal.polkorab
*/
public class ExperimenterDeserializerKeyFactoryTest {
43L, ExperimenterDataOfChoice.class);
Assert.assertEquals("Wrong key created", comparationKey, createdKey);
}
-}
\ No newline at end of file
+}
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.table.features.properties.grouping.TableFeatureProperties;
/**
- * Test ExperimenterSerializerKeyFactory key creation
- * @author michal.polkorab
+ * Test ExperimenterSerializerKeyFactory key creation.
*
+ * @author michal.polkorab
*/
public class ExperimenterSerializerKeyFactoryTest {
@Test
public void testCreateMeterBandSubTypeSerializerKey() throws Exception {
- ExperimenterIdSerializerKey<?> createdKey;
- ExperimenterIdSerializerKey<?> comparationKey1;
- ExperimenterIdSerializerKey<?> comparationKey2;
- ExperimenterIdSerializerKey<?> comparationKey3;
- ExperimenterIdSerializerKey<?> comparationKey4;
- ExperimenterIdSerializerKey<?> comparationKey5;
+ final ExperimenterIdSerializerKey<?> createdKey;
+ final ExperimenterIdSerializerKey<?> comparationKey1;
+ final ExperimenterIdSerializerKey<?> comparationKey2;
+ final ExperimenterIdSerializerKey<?> comparationKey3;
+ final ExperimenterIdSerializerKey<?> comparationKey4;
+ final ExperimenterIdSerializerKey<?> comparationKey5;
createdKey = ExperimenterSerializerKeyFactory.createMeterBandSerializerKey(
EncodeConstants.OF10_VERSION_ID, 43L, ExperimenterMeterBandSubType.class);
Assert.assertNotEquals("Wrong key created", comparationKey4, createdKey);
Assert.assertEquals("Wrong key created", comparationKey5, createdKey);
}
-}
\ No newline at end of file
+}