* 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.instruction;
import io.netty.buffer.ByteBuf;
-import java.util.ArrayList;
-import java.util.List;
+import java.util.Map;
import org.opendaylight.openflowjava.protocol.api.extensibility.DeserializerRegistry;
import org.opendaylight.openflowjava.protocol.api.extensibility.DeserializerRegistryInjector;
import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
import org.opendaylight.openflowjava.protocol.impl.util.InstructionConstants;
import org.opendaylight.openflowplugin.extension.api.path.ActionPath;
import org.opendaylight.openflowplugin.impl.protocol.deserialization.util.ActionUtil;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action;
import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionKey;
+import org.opendaylight.yangtools.yang.binding.util.BindingMap;
public abstract class AbstractActionInstructionDeserializer extends AbstractInstructionDeserializer
implements DeserializerRegistryInjector {
* @param message Openflow buffered message
* @return instruction length
**/
- protected static int readHeader(ByteBuf message) {
+ protected static int readHeader(final ByteBuf message) {
message.skipBytes(Short.BYTES);
return message.readUnsignedShort();
}
* @param length instruction length
* @return list of actions
**/
- protected List<org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list
- .Action> readActions(ByteBuf message, int length) {
+ protected Map<ActionKey, Action> readActions(final ByteBuf message, final int length) {
+ if (message.readableBytes() <= 0) {
+ return Map.of();
+ }
final int instrLength = length - InstructionConstants.STANDARD_INSTRUCTION_LENGTH;
+ final var actions = BindingMap.<ActionKey, Action>orderedBuilder();
+ final int startIndex = message.readerIndex();
+ int offset = 0;
- final List<org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list
- .Action> actions = new ArrayList<>();
-
- if (message.readableBytes() > 0) {
- final int startIndex = message.readerIndex();
- int offset = 0;
-
- while ((message.readerIndex() - startIndex) < instrLength) {
- actions.add(new ActionBuilder()
- .withKey(new ActionKey(offset))
- .setOrder(offset)
- .setAction(ActionUtil
- .readAction(EncodeConstants.OF13_VERSION_ID, message, registry, actionPath))
- .build());
-
- offset++;
- }
+ while (message.readerIndex() - startIndex < instrLength) {
+ actions.add(new ActionBuilder()
+ .setOrder(offset++)
+ .setAction(ActionUtil.readAction(EncodeConstants.OF13_VERSION_ID, message, registry, actionPath))
+ .build());
}
- return actions;
+ return actions.build();
}
@Override
- public void injectDeserializerRegistry(DeserializerRegistry deserializerRegistry) {
+ public void injectDeserializerRegistry(final DeserializerRegistry deserializerRegistry) {
registry = deserializerRegistry;
}
* 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 io.netty.buffer.ByteBuf;
-import java.util.ArrayList;
-import java.util.List;
import org.opendaylight.openflowjava.protocol.api.extensibility.DeserializerRegistry;
import org.opendaylight.openflowjava.protocol.api.extensibility.DeserializerRegistryInjector;
import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer;
import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
import org.opendaylight.openflowplugin.extension.api.path.ActionPath;
import org.opendaylight.openflowplugin.impl.protocol.deserialization.util.ActionUtil;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action;
import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionKey;
import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.multipart.reply.multipart.reply.body.MultipartReplyGroupDescBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.desc.stats.reply.GroupDescStatsBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.desc.stats.reply.GroupDescStatsKey;
import org.opendaylight.yang.gen.v1.urn.opendaylight.multipart.types.rev170112.multipart.reply.MultipartReplyBody;
+import org.opendaylight.yangtools.yang.binding.util.BindingMap;
public class MultipartReplyGroupDescDeserializer implements OFDeserializer<MultipartReplyBody>,
DeserializerRegistryInjector {
private DeserializerRegistry registry;
@Override
- public MultipartReplyBody deserialize(ByteBuf message) {
+ public MultipartReplyBody deserialize(final ByteBuf message) {
final MultipartReplyGroupDescBuilder builder = new MultipartReplyGroupDescBuilder();
- final List<GroupDescStats> items = new ArrayList<>();
+ final var items = BindingMap.<GroupDescStatsKey, GroupDescStats>orderedBuilder();
while (message.readableBytes() > 0) {
final int itemLength = message.readUnsignedShort();
itemBuilder.setGroupId(new GroupId(message.readUnsignedInt()));
itemBuilder.withKey(new GroupDescStatsKey(itemBuilder.getGroupId()));
- final List<Bucket> subItems = new ArrayList<>();
+ final var subItems = BindingMap.<BucketKey, Bucket>orderedBuilder();
int actualLength = GROUP_DESC_HEADER_LENGTH;
long bucketKey = 0;
.setWatchGroup(message.readUnsignedInt());
message.skipBytes(PADDING_IN_BUCKETS_HEADER);
- final List<org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list
- .Action> actions = new ArrayList<>();
+ final var actions = BindingMap.<ActionKey, Action>orderedBuilder();
final int startIndex = message.readerIndex();
final int bucketLength = bucketsLength - BUCKETS_HEADER_LENGTH;
int offset = 0;
offset++;
}
- bucketBuilder.setAction(actions);
- subItems.add(bucketBuilder.build());
+ subItems.add(bucketBuilder.setAction(actions.build()).build());
bucketKey++;
actualLength += bucketsLength;
}
- items.add(itemBuilder
- .setBuckets(new BucketsBuilder()
- .setBucket(subItems)
- .build())
- .build());
+ items.add(itemBuilder.setBuckets(new BucketsBuilder().setBucket(subItems.build()).build()).build());
}
- return builder
- .setGroupDescStats(items)
- .build();
+ return builder.setGroupDescStats(items.build()).build();
}
@Override
- public void injectDeserializerRegistry(DeserializerRegistry deserializerRegistry) {
+ public void injectDeserializerRegistry(final DeserializerRegistry deserializerRegistry) {
registry = deserializerRegistry;
}
import io.netty.buffer.ByteBuf;
import java.util.ArrayList;
import java.util.List;
+import java.util.Map;
import org.opendaylight.openflowjava.protocol.api.extensibility.DeserializerRegistry;
import org.opendaylight.openflowjava.protocol.api.extensibility.DeserializerRegistryInjector;
import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer;
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.binding.util.BindingMap;
import org.opendaylight.yangtools.yang.common.Uint8;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
}
@SuppressWarnings("checkstyle:LineLength")
- private List<Action> readActions(final ByteBuf message, final int length) {
- final List<Action> actions = new ArrayList<>();
+ private Map<ActionKey, Action> readActions(final ByteBuf message, final int length) {
+ final var actions = BindingMap.<ActionKey, Action>orderedBuilder();
final int startIndex = message.readerIndex();
int offset = 0;
offset++;
} catch (ClassCastException | IllegalStateException e) {
+ LOG.debug("Failed to build action", e);
+ // FIXME: what are we guarding here?
message.skipBytes(2 * Short.BYTES);
}
}
- return actions;
+ return actions.build();
}
@Override
// merge is expensive and not applicable for lists
if (flowCapNodeOpt != null && flowCapNodeOpt.isPresent()) {
for (final Table tableData : flowCapNodeOpt.get().nonnullTable().values()) {
- final Table table = new TableBuilder(tableData).setFlow(Collections.emptyList()).build();
+ final Table table = new TableBuilder(tableData).setFlow(Collections.emptyMap()).build();
final InstanceIdentifier<Table> iiToTable = instanceIdentifier
.child(Table.class, tableData.key());
txFacade.writeToTransaction(LogicalDatastoreType.OPERATIONAL, iiToTable, table);
package org.opendaylight.openflowplugin.impl.statistics.services;
import com.google.common.util.concurrent.ListenableFuture;
-import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.atomic.AtomicLong;
import org.opendaylight.mdsal.binding.api.NotificationPublishService;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.OpendaylightFlowTableStatisticsService;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.flow.table.and.statistics.map.FlowTableAndStatisticsMap;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.flow.table.and.statistics.map.FlowTableAndStatisticsMapBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.flow.table.and.statistics.map.FlowTableAndStatisticsMapKey;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.transaction.rev150304.TransactionId;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartType;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReply;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestTableCaseBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.table._case.MultipartRequestTableBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.TableId;
+import org.opendaylight.yangtools.yang.binding.util.BindingMap;
import org.opendaylight.yangtools.yang.common.Empty;
import org.opendaylight.yangtools.yang.common.RpcResult;
}
@Override
- public GetFlowTablesStatisticsOutput buildTxCapableResult(TransactionId emulatedTxId) {
+ public GetFlowTablesStatisticsOutput buildTxCapableResult(final TransactionId emulatedTxId) {
return new GetFlowTablesStatisticsOutputBuilder().setTransactionId(emulatedTxId).build();
}
@Override
- public FlowTableStatisticsUpdate transformToNotification(List<MultipartReply> mpReplyList,
- TransactionId emulatedTxId) {
+ public FlowTableStatisticsUpdate transformToNotification(final List<MultipartReply> mpReplyList,
+ final TransactionId emulatedTxId) {
FlowTableStatisticsUpdateBuilder notification = new FlowTableStatisticsUpdateBuilder();
notification.setId(getDeviceInfo().getNodeId());
notification.setMoreReplies(Boolean.FALSE);
notification.setTransactionId(emulatedTxId);
- final List<FlowTableAndStatisticsMap> salFlowStats = new ArrayList<>();
- notification.setFlowTableAndStatisticsMap(salFlowStats);
+ final var salFlowStats = BindingMap.<FlowTableAndStatisticsMapKey, FlowTableAndStatisticsMap>orderedBuilder();
for (MultipartReply mpReply : mpReplyList) {
MultipartReplyTableCase caseBody = (MultipartReplyTableCase) mpReply.getMultipartReplyBody();
MultipartReplyTable replyBody = caseBody.getMultipartReplyTable();
- List<TableStats> swTablesStats = replyBody.getTableStats();
//TODO: Duplicate code: look at MultiReplyTranslatorUtil method translateTable
- for (TableStats swTableStats : swTablesStats) {
+ for (TableStats swTableStats : replyBody.nonnullTableStats()) {
FlowTableAndStatisticsMapBuilder statisticsBuilder = new FlowTableAndStatisticsMapBuilder();
statisticsBuilder.setActiveFlows(new Counter32(swTableStats.getActiveCount()));
statisticsBuilder.setPacketsLookedUp(new Counter64(swTableStats.getLookupCount()));
}
}
- return notification.build();
+ return notification.setFlowTableAndStatisticsMap(salFlowStats.build()).build();
}
}
builder.setPeerFeatures(PortTranslatorUtil.translatePortFeatures(input.getPeerFeatures()));
builder.setState(PortTranslatorUtil.translatePortState(input.getState()));
builder.setSupported(PortTranslatorUtil.translatePortFeatures(input.getSupportedFeatures()));
- builder.setQueue(Collections
- .emptyList());
+ builder.setQueue(Collections.emptyMap());
}
if (input instanceof PortStatusMessage) {
if (((PortStatusMessage) input).getReason() != null) {