import com.google.common.base.MoreObjects;
import com.google.common.base.Preconditions;
import com.google.common.util.concurrent.Futures;
+import com.google.common.util.concurrent.ListenableFuture;
+import com.google.common.util.concurrent.MoreExecutors;
import java.util.List;
-import java.util.concurrent.Future;
+import java.util.Optional;
import java.util.stream.Collectors;
import org.opendaylight.openflowplugin.api.OFConstants;
import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
import org.opendaylight.openflowplugin.impl.services.AbstractAggregateFlowMultipartService;
import org.opendaylight.openflowplugin.impl.services.util.RequestInputUtils;
import org.opendaylight.openflowplugin.impl.services.util.ServiceException;
+import org.opendaylight.openflowplugin.impl.util.FlowCreatorUtil;
import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorExecutor;
-import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.match.MatchReactor;
-import org.opendaylight.openflowplugin.openflow.md.util.FlowCreatorUtil;
+import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.data.VersionConvertorData;
+import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.match.MatchInjector;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAggregateFlowStatisticsFromFlowTableForGivenMatchInput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutputBuilder;
private final TranslatorLibrary translatorLibrary;
private final ConvertorExecutor convertorExecutor;
+ private final VersionConvertorData data;
public MultiLayerAggregateFlowMultipartService(final RequestContextStack requestContextStack,
final DeviceContext deviceContext,
super(requestContextStack, deviceContext);
this.convertorExecutor = convertorExecutor;
this.translatorLibrary = translatorLibrary;
+ this.data = new VersionConvertorData(getVersion());
}
@Override
- protected OfHeader buildRequest(final Xid xid, final GetAggregateFlowStatisticsFromFlowTableForGivenMatchInput input) throws ServiceException {
- final MultipartRequestAggregateCaseBuilder multipartRequestAggregateCaseBuilder = new MultipartRequestAggregateCaseBuilder();
+ protected OfHeader buildRequest(final Xid xid,
+ final GetAggregateFlowStatisticsFromFlowTableForGivenMatchInput input) throws
+ ServiceException {
+ final MultipartRequestAggregateCaseBuilder multipartRequestAggregateCaseBuilder
+ = new MultipartRequestAggregateCaseBuilder();
final MultipartRequestAggregateBuilder mprAggregateRequestBuilder = new MultipartRequestAggregateBuilder();
final short tableId = MoreObjects.firstNonNull(input.getTableId(), OFConstants.OFPTT_ALL);
mprAggregateRequestBuilder.setTableId(tableId);
if (input.getCookie() == null) {
mprAggregateRequestBuilder.setCookie(OFConstants.DEFAULT_COOKIE);
} else {
- mprAggregateRequestBuilder.setCookie(MoreObjects.firstNonNull(input.getCookie().getValue(), OFConstants.DEFAULT_COOKIE));
+ mprAggregateRequestBuilder
+ .setCookie(MoreObjects.firstNonNull(input.getCookie().getValue(), OFConstants.DEFAULT_COOKIE));
}
if (input.getCookieMask() == null) {
mprAggregateRequestBuilder.setCookieMask(OFConstants.DEFAULT_COOKIE_MASK);
} else {
- mprAggregateRequestBuilder.setCookieMask(MoreObjects.firstNonNull(input.getCookieMask().getValue(), OFConstants.DEFAULT_COOKIE_MASK));
+ mprAggregateRequestBuilder.setCookieMask(
+ MoreObjects.firstNonNull(input.getCookieMask().getValue(), OFConstants.DEFAULT_COOKIE_MASK));
}
long outGroup = MoreObjects.firstNonNull(input.getOutGroup(), OFConstants.OFPG_ANY);
mprAggregateRequestBuilder.setOutGroup(outGroup);
mprAggregateRequestBuilder.setCookieMask(OFConstants.DEFAULT_COOKIE_MASK);
}
- MatchReactor.getInstance().convert(input.getMatch(), version, mprAggregateRequestBuilder, convertorExecutor);
+ // convert and inject match
+ final Optional<Object> conversionMatch = convertorExecutor.convert(input.getMatch(), data);
+ MatchInjector.inject(conversionMatch, mprAggregateRequestBuilder, data.getVersion());
FlowCreatorUtil.setWildcardedFlowMatch(version, mprAggregateRequestBuilder);
// Set request body to main multipart request
- multipartRequestAggregateCaseBuilder.setMultipartRequestAggregate(mprAggregateRequestBuilder
- .build());
+ multipartRequestAggregateCaseBuilder.setMultipartRequestAggregate(mprAggregateRequestBuilder.build());
- final MultipartRequestInputBuilder mprInput = RequestInputUtils.createMultipartHeader(
- MultipartType.OFPMPAGGREGATE, xid.getValue(), version);
+ final MultipartRequestInputBuilder mprInput = RequestInputUtils
+ .createMultipartHeader(MultipartType.OFPMPAGGREGATE, xid.getValue(), version);
mprInput.setMultipartRequestBody(multipartRequestAggregateCaseBuilder.build());
}
@Override
- public Future<RpcResult<GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutput>> handleAndReply(final GetAggregateFlowStatisticsFromFlowTableForGivenMatchInput input) {
+ public ListenableFuture<RpcResult<GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutput>> handleAndReply(
+ final GetAggregateFlowStatisticsFromFlowTableForGivenMatchInput input) {
return Futures.transform(handleServiceCall(input),
- (Function<RpcResult<List<MultipartReply>>, RpcResult<GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutput>>) result -> {
+ (Function<RpcResult<List<MultipartReply>>,
+ RpcResult<GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutput>>)
+ result -> {
if (Preconditions.checkNotNull(result).isSuccessful()) {
- final MessageTranslator<MultipartReply, AggregatedFlowStatistics> messageTranslator = translatorLibrary
- .lookupTranslator(new TranslatorKey(getVersion(), MultipartReplyAggregateCase.class.getName()));
-
- return RpcResultBuilder
- .success(new GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutputBuilder()
- .setAggregatedFlowStatistics(result
- .getResult()
- .stream()
- .map(multipartReply -> messageTranslator
- .translate(multipartReply, getDeviceInfo(), null))
- .collect(Collectors.toList())))
- .build();
+ final MessageTranslator<MultipartReply, AggregatedFlowStatistics>
+ messageTranslator = translatorLibrary.lookupTranslator(
+ new TranslatorKey(getVersion(),
+ MultipartReplyAggregateCase.class.getName()));
+
+ return RpcResultBuilder.success(
+ new GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutputBuilder()
+ .setAggregatedFlowStatistics(result.getResult().stream()
+ .map(multipartReply ->
+ messageTranslator
+ .translate(
+ multipartReply,
+ getDeviceInfo(),
+ null))
+ .collect(Collectors
+ .toList())))
+ .build();
}
return RpcResultBuilder
- .<GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutput>failed()
- .withRpcErrors(result.getErrors())
- .build();
- });
+ .<GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutput>failed()
+ .withRpcErrors(result.getErrors()).build();
+ }, MoreExecutors.directExecutor());
}
-
}