* terms of the Eclipse Public License v1.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
-
package org.opendaylight.openflowplugin.impl.protocol.deserialization.multipart;
+import static org.opendaylight.yangtools.yang.common.netty.ByteBufUtils.readUint32;
+import static org.opendaylight.yangtools.yang.common.netty.ByteBufUtils.readUint64;
+import static org.opendaylight.yangtools.yang.common.netty.ByteBufUtils.readUint8;
+
import io.netty.buffer.ByteBuf;
-import java.math.BigInteger;
import java.util.ArrayList;
import java.util.List;
import org.opendaylight.openflowjava.protocol.api.extensibility.DeserializerRegistry;
import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.features.table.features.table.properties.TableFeatureProperties;
import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.features.table.features.table.properties.TableFeaturePropertiesBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.features.table.features.table.properties.TableFeaturePropertiesKey;
+import org.opendaylight.yangtools.yang.common.Uint8;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
private DeserializerRegistry registry;
@Override
- public MultipartReplyBody deserialize(ByteBuf message) {
+ public MultipartReplyBody deserialize(final ByteBuf message) {
final MultipartReplyTableFeaturesBuilder builder = new MultipartReplyTableFeaturesBuilder();
final List<TableFeatures> items = new ArrayList<>();
while (message.readableBytes() > 0) {
final int itemLength = message.readUnsignedShort();
final TableFeaturesBuilder itemBuilder = new TableFeaturesBuilder()
- .setTableId(message.readUnsignedByte());
+ .setTableId(readUint8(message));
message.skipBytes(PADDING_IN_MULTIPART_REPLY_TABLE_FEATURES);
- final String name = ByteBufUtils.decodeNullTerminatedString(message, MAX_TABLE_NAME_LENGTH);
- final byte[] match = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
- message.readBytes(match);
- final byte[] write = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
- message.readBytes(write);
-
items.add(itemBuilder
- .setKey(new TableFeaturesKey(itemBuilder.getTableId()))
- .setName(name)
- .setMetadataMatch(new BigInteger(1, match))
- .setMetadataWrite(new BigInteger(1, write))
+ .withKey(new TableFeaturesKey(itemBuilder.getTableId()))
+ .setName(ByteBufUtils.decodeNullTerminatedString(message, MAX_TABLE_NAME_LENGTH))
+ .setMetadataMatch(readUint64(message))
+ .setMetadataWrite(readUint64(message))
.setConfig(readTableConfig(message))
- .setMaxEntries(message.readUnsignedInt())
+ .setMaxEntries(readUint32(message))
.setTableProperties(readTableProperties(message,
itemLength - MULTIPART_REPLY_TABLE_FEATURES_STRUCTURE_LENGTH))
.build());
.build();
}
- private TableConfig readTableConfig(ByteBuf message) {
+ private static TableConfig readTableConfig(final ByteBuf message) {
final long input = message.readUnsignedInt();
final boolean deprecated = (input & 3) != 0;
return new TableConfig(deprecated);
}
- private TableProperties readTableProperties(ByteBuf message, int length) {
+ private TableProperties readTableProperties(final ByteBuf message, final int length) {
final List<TableFeatureProperties> items = new ArrayList<>();
int tableFeaturesLength = length;
int order = 0;
final int commonPropertyLength = propertyLength - COMMON_PROPERTY_LENGTH;
final TableFeaturePropertiesBuilder propBuilder = new TableFeaturePropertiesBuilder()
.setOrder(order)
- .setKey(new TableFeaturePropertiesKey(order));
+ .withKey(new TableFeaturePropertiesKey(order));
switch (propType) {
case OFPTFPTINSTRUCTIONS:
.build();
}
- private List<SetFieldMatch> readMatchFields(ByteBuf message, int length) {
+ private static List<SetFieldMatch> readMatchFields(final ByteBuf message, final int length) {
final List<SetFieldMatch> matchFields = new ArrayList<>();
final int startIndex = message.readerIndex();
- while ((message.readerIndex() - startIndex) < length) {
+ while (message.readerIndex() - startIndex < length) {
MATCH_FIELD_DESERIALIZER
.deserialize(message)
.map(matchFields::add)
.orElseGet(() -> {
- message.skipBytes(2 * EncodeConstants.SIZE_OF_SHORT_IN_BYTES);
+ message.skipBytes(2 * Short.BYTES);
return Boolean.FALSE;
});
}
return matchFields;
}
- private List<Short> readNextTableIds(ByteBuf message, int length) {
- final List<Short> tableIds = new ArrayList<>();
+ private static List<Uint8> readNextTableIds(final ByteBuf message, final int length) {
+ final List<Uint8> tableIds = new ArrayList<>();
int nextTableLength = length;
while (nextTableLength > 0) {
- tableIds.add(message.readUnsignedByte());
+ tableIds.add(Uint8.valueOf(message.readUnsignedByte()));
nextTableLength -= 1;
}
}
private List<org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list
- .Instruction> readInstructions(ByteBuf message, int length) {
+ .Instruction> readInstructions(final ByteBuf message, final int length) {
final List<org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list
.Instruction> instructions = new ArrayList<>();
final int startIndex = message.readerIndex();
int offset = 0;
- while ((message.readerIndex() - startIndex) < length) {
+ while (message.readerIndex() - startIndex < length) {
try {
instructions.add(new InstructionBuilder()
- .setKey(new InstructionKey(offset))
+ .withKey(new InstructionKey(offset))
.setOrder(offset)
.setInstruction(InstructionUtil
.readInstructionHeader(EncodeConstants.OF13_VERSION_ID, message, registry))
offset++;
} catch (ClassCastException | IllegalStateException e) {
- message.skipBytes(2 * EncodeConstants.SIZE_OF_SHORT_IN_BYTES);
+ message.skipBytes(2 * Short.BYTES);
}
}
}
@SuppressWarnings("checkstyle:LineLength")
- private List<Action> readActions(ByteBuf message, int length) {
+ private List<Action> readActions(final ByteBuf message, final int length) {
final List<Action> actions = new ArrayList<>();
final int startIndex = message.readerIndex();
int offset = 0;
- while ((message.readerIndex() - startIndex) < length) {
+ while (message.readerIndex() - startIndex < length) {
try {
actions.add(new ActionBuilder()
- .setKey(new ActionKey(offset))
+ .withKey(new ActionKey(offset))
.setOrder(offset)
.setAction(ActionUtil.readActionHeader(EncodeConstants.OF13_VERSION_ID, message, registry,
- ActionPath
- .FLOWSSTATISTICSUPDATE_FLOWANDSTATISTICSMAPLIST_INSTRUCTIONS_INSTRUCTION_INSTRUCTION_APPLYACTIONSCASE_APPLYACTIONS_ACTION_ACTION))
+ ActionPath.FLOWS_STATISTICS_UPDATE_APPLY_ACTIONS))
.build());
offset++;
} catch (ClassCastException | IllegalStateException e) {
- message.skipBytes(2 * EncodeConstants.SIZE_OF_SHORT_IN_BYTES);
+ message.skipBytes(2 * Short.BYTES);
}
}
}
@Override
- public void injectDeserializerRegistry(DeserializerRegistry deserializerRegistry) {
+ public void injectDeserializerRegistry(final DeserializerRegistry deserializerRegistry) {
registry = deserializerRegistry;
}