X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=openflowplugin%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fopenflowplugin%2Fopenflow%2Fmd%2Fcore%2Fsal%2Fconvertor%2Fflow%2FFlowStatsResponseConvertor.java;h=192c83cfca49970a7931905afa86912c578ef77f;hb=f7b6593eaad290c8c1cbd592e9972729a9a953b8;hp=84c8b69e2a51821c5e7d66f43b495d295563c250;hpb=ddf1b1a5e0f3d401f562945ceb473570641fb45e;p=openflowplugin.git diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/flow/FlowStatsResponseConvertor.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/flow/FlowStatsResponseConvertor.java index 84c8b69e2a..192c83cfca 100644 --- a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/flow/FlowStatsResponseConvertor.java +++ b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/flow/FlowStatsResponseConvertor.java @@ -5,7 +5,6 @@ * 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.openflow.md.core.sal.convertor.flow; import java.util.ArrayList; @@ -17,12 +16,11 @@ import java.util.Set; import org.opendaylight.openflowplugin.api.openflow.md.util.OpenflowVersion; import org.opendaylight.openflowplugin.extension.api.AugmentTuple; import org.opendaylight.openflowplugin.extension.api.path.ActionPath; -import org.opendaylight.openflowplugin.extension.api.path.MatchPath; import org.opendaylight.openflowplugin.openflow.md.core.extension.MatchExtensionHelper; import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.data.ActionResponseConvertorData; import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.Convertor; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.data.FlowStatsResponseConvertorData; import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.data.VersionConvertorData; -import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.data.VersionDatapathIdConvertorData; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Counter32; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Counter64; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.flow.and.statistics.map.list.FlowAndStatisticsMapList; @@ -35,16 +33,17 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.M import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.ApplyActionsCaseBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.apply.actions._case.ApplyActionsBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.Instruction; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.InstructionBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.InstructionKey; +import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.IpMatch; import org.opendaylight.yang.gen.v1.urn.opendaylight.model.statistics.types.rev130925.duration.DurationBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.flow._case.multipart.reply.flow.FlowStats; -import org.opendaylight.yangtools.yang.binding.DataContainer; +import org.opendaylight.yangtools.yang.binding.util.BindingMap; +import org.opendaylight.yangtools.yang.common.Uint8; /** * Converts flow related statistics messages coming from openflow switch to MD-SAL messages. * + *

* Example usage: *

  * {@code
@@ -54,49 +53,51 @@ import org.opendaylight.yangtools.yang.binding.DataContainer;
  * }
  * 
*/ -public class FlowStatsResponseConvertor extends Convertor, List, VersionDatapathIdConvertorData> { +public class FlowStatsResponseConvertor extends Convertor, List, + FlowStatsResponseConvertorData> { - private static final Set> TYPES = Collections.singleton(FlowStats.class); + private static final Set> TYPES = Collections.singleton(FlowStats.class); /** - * Method wraps openflow 1.0 actions list to Apply Action Instructions + * Method wraps openflow 1.0 actions list to Apply Action Instructions. * * @param actionsList list of action + * @param ipProtocol ip protocol * @return OF10 actions as an instructions */ - private Instructions wrapOF10ActionsToInstruction(List actionsList, final short version) { + private Instructions wrapOF10ActionsToInstruction( + final List actionsList, + final Uint8 version, final Uint8 ipProtocol) { ActionResponseConvertorData actionResponseConvertorData = new ActionResponseConvertorData(version); - actionResponseConvertorData.setActionPath(ActionPath.FLOWSSTATISTICSUPDATE_FLOWANDSTATISTICSMAPLIST_INSTRUCTIONS_INSTRUCTION_INSTRUCTION_WRITEACTIONSCASE_WRITEACTIONS_ACTION_ACTION); - - InstructionsBuilder instructionsBuilder = new InstructionsBuilder(); - List salInstructionList = new ArrayList<>(); + actionResponseConvertorData.setActionPath(ActionPath.FLOWS_STATISTICS_UPDATE_WRITE_ACTIONS); + actionResponseConvertorData.setIpProtocol(ipProtocol); ApplyActionsCaseBuilder applyActionsCaseBuilder = new ApplyActionsCaseBuilder(); ApplyActionsBuilder applyActionsBuilder = new ApplyActionsBuilder(); - final Optional> actions = getConvertorExecutor().convert( - actionsList, actionResponseConvertorData); + final Optional> + actions = getConvertorExecutor().convert(actionsList, actionResponseConvertorData); applyActionsBuilder.setAction(FlowConvertorUtil.wrapActionList(actions.orElse(Collections.emptyList()))); applyActionsCaseBuilder.setApplyActions(applyActionsBuilder.build()); - InstructionBuilder instBuilder = new InstructionBuilder(); - instBuilder.setInstruction(applyActionsCaseBuilder.build()); - instBuilder.setKey(new InstructionKey(0)); - instBuilder.setOrder(0); - salInstructionList.add(instBuilder.build()); - - instructionsBuilder.setInstruction(salInstructionList); - return instructionsBuilder.build(); + return new InstructionsBuilder() + .setInstruction(BindingMap.of(new InstructionBuilder() + .setInstruction(applyActionsCaseBuilder.build()) + .setOrder(0) + .build())) + .build(); } @Override - public Collection> getTypes() { + public Collection> getTypes() { return TYPES; } @Override - public List convert(List source, VersionDatapathIdConvertorData data) { + public List convert(final List source, + final FlowStatsResponseConvertorData data) { final List result = new ArrayList<>(); for (FlowStats flowStats : source) { @@ -120,31 +121,41 @@ public class FlowStatsResponseConvertor extends Convertor, List< salFlowStatsBuilder.setTableId(flowStats.getTableId()); if (flowStats.getMatchV10() != null) { - final Optional matchBuilderOptional = getConvertorExecutor().convert(flowStats.getMatchV10(), data); + final Optional matchBuilderOptional = getConvertorExecutor().convert( + flowStats.getMatchV10(), data); + Uint8 ipProtocol = null; if (matchBuilderOptional.isPresent()) { - salFlowStatsBuilder.setMatch(matchBuilderOptional.get().build()); + final MatchBuilder matchBuilder = matchBuilderOptional.orElseThrow(); + final IpMatch ipMatch = matchBuilder.getIpMatch(); + if (ipMatch != null) { + ipProtocol = ipMatch.getIpProtocol(); + } + + salFlowStatsBuilder.setMatch(matchBuilder.build()); } if (flowStats.getAction() != null && flowStats.getAction().size() != 0) { - salFlowStatsBuilder.setInstructions(wrapOF10ActionsToInstruction(flowStats.getAction(), data.getVersion())); + salFlowStatsBuilder.setInstructions(wrapOF10ActionsToInstruction(flowStats.getAction(), + data.getVersion(), ipProtocol)); } } if (flowStats.getMatch() != null) { - final Optional matchBuilderOptional = getConvertorExecutor().convert(flowStats.getMatch(), data); + final Optional matchBuilderOptional = getConvertorExecutor().convert( + flowStats.getMatch(), data); if (matchBuilderOptional.isPresent()) { - final MatchBuilder matchBuilder = matchBuilderOptional.get(); + final MatchBuilder matchBuilder = matchBuilderOptional.orElseThrow(); final AugmentTuple matchExtensionWrap = MatchExtensionHelper.processAllExtensions( - flowStats.getMatch().getMatchEntry(), + flowStats.getMatch().nonnullMatchEntry(), OpenflowVersion.get(data.getVersion()), - MatchPath.FLOWSSTATISTICSUPDATE_FLOWANDSTATISTICSMAPLIST_MATCH); + data.getMatchPath()); if (matchExtensionWrap != null) { - matchBuilder.addAugmentation(matchExtensionWrap.getAugmentationClass(), matchExtensionWrap.getAugmentationObject()); + matchBuilder.addAugmentation(matchExtensionWrap.getAugmentationObject()); } salFlowStatsBuilder.setMatch(matchBuilder.build()); @@ -152,11 +163,11 @@ public class FlowStatsResponseConvertor extends Convertor, List< salFlowStatsBuilder.setFlags( - new FlowModFlags(flowStats.getFlags().isOFPFFCHECKOVERLAP(), - flowStats.getFlags().isOFPFFRESETCOUNTS(), - flowStats.getFlags().isOFPFFNOPKTCOUNTS(), - flowStats.getFlags().isOFPFFNOBYTCOUNTS(), - flowStats.getFlags().isOFPFFSENDFLOWREM())); + new FlowModFlags(flowStats.getFlags().getOFPFFCHECKOVERLAP(), + flowStats.getFlags().getOFPFFRESETCOUNTS(), + flowStats.getFlags().getOFPFFNOPKTCOUNTS(), + flowStats.getFlags().getOFPFFNOBYTCOUNTS(), + flowStats.getFlags().getOFPFFSENDFLOWREM())); } if (flowStats.getInstruction() != null) { @@ -165,7 +176,7 @@ public class FlowStatsResponseConvertor extends Convertor, List< flowStats.getInstruction(), simpleConvertorData); salFlowStatsBuilder.setInstructions(instructions.orElse(new InstructionsBuilder() - .setInstruction(Collections.emptyList()).build())); + .setInstruction(Collections.emptyMap()).build())); } result.add(salFlowStatsBuilder.build());