From d7510952ad1add03ee34bc96bf1a68daa2d5a59a Mon Sep 17 00:00:00 2001 From: Tomas Slusny Date: Wed, 29 Jun 2016 09:08:38 +0200 Subject: [PATCH] Bug 5540 - FlowConvertor, FlowStatsResponseConvertor, FlowInstructionResponseConvertor - Reworked FlowConvertor, FlowStatsResponseConvertor to use new ConvertorManager design - Added FlowInstructionResponseConvertor (moved some loic from FlowStatsResponseConvertor) - Updated tests and usages accordingly Change-Id: Iff2dc752aab73473adb955394cf852d7524fddd9 Signed-off-by: Tomas Slusny --- .../impl/services/FlowService.java | 11 +- ...SinglePurposeMultipartReplyTranslator.java | 18 +- ...owStatisticsToNotificationTransformer.java | 21 +- .../direct/FlowDirectStatisticsService.java | 32 ++- .../md/core/sal/OFRpcTaskFactory.java | 48 ++-- .../core/sal/convertor/ConvertorManager.java | 6 + .../convertor/FlowStatsResponseConvertor.java | 130 --------- .../convertor/{ => flow}/FlowConvertor.java | 263 +++++++----------- .../sal/convertor/flow/FlowConvertorUtil.java | 62 +++++ .../FlowInstructionResponseConvertor.java} | 132 +++------ .../flow/FlowStatsResponseConvertor.java | 174 ++++++++++++ .../flow/cases/ApplyActionsCase.java | 46 +++ .../flow/cases/ClearActionsCase.java | 32 +++ .../convertor/flow/cases/GoToTableCase.java | 38 +++ .../sal/convertor/flow/cases/MeterCase.java | 39 +++ .../flow/cases/WriteActionsCase.java | 46 +++ .../flow/cases/WriteMetadataCase.java | 40 +++ .../flowflag/FlowFlagConvertor.java | 7 +- .../{ => flow}/flowflag/FlowFlagReactor.java | 7 +- .../FlowFlagReactorMappingFactory.java | 30 +- .../flowflag/FlowFlagsConvertorImpl.java | 20 +- .../flowflag/FlowFlagsConvertorV10Impl.java | 21 +- .../match/MatchReactorMappingFactory.java | 2 +- .../translator/MultipartReplyTranslator.java | 11 +- .../openflow/md/util/FlowCreatorUtil.java | 2 +- .../core/sal/convertor/FlowConverterTest.java | 231 --------------- .../action/ActionConvertorV10Test.java | 5 +- .../action/ActionConvertorV13Test.java | 6 +- .../{ => flow}/FlowConvertorTest.java | 231 ++++++++++++++- .../FlowStatsResponseConvertorTest.java} | 40 ++- .../flowflag/FlowFlagReactorTest.java | 2 +- 31 files changed, 994 insertions(+), 759 deletions(-) delete mode 100644 openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/FlowStatsResponseConvertor.java rename openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/{ => flow}/FlowConvertor.java (63%) create mode 100644 openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/flow/FlowConvertorUtil.java rename openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/{OFToMDSalFlowConvertor.java => flow/FlowInstructionResponseConvertor.java} (64%) create mode 100644 openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/flow/FlowStatsResponseConvertor.java create mode 100644 openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/flow/cases/ApplyActionsCase.java create mode 100644 openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/flow/cases/ClearActionsCase.java create mode 100644 openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/flow/cases/GoToTableCase.java create mode 100644 openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/flow/cases/MeterCase.java create mode 100644 openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/flow/cases/WriteActionsCase.java create mode 100644 openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/flow/cases/WriteMetadataCase.java rename openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/{ => flow}/flowflag/FlowFlagConvertor.java (93%) rename openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/{ => flow}/flowflag/FlowFlagReactor.java (92%) rename openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/{ => flow}/flowflag/FlowFlagReactorMappingFactory.java (80%) rename openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/{ => flow}/flowflag/FlowFlagsConvertorImpl.java (80%) rename openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/{ => flow}/flowflag/FlowFlagsConvertorV10Impl.java (75%) delete mode 100644 openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/FlowConverterTest.java rename openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/{ => flow}/FlowConvertorTest.java (60%) rename openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/{OFToMDSalFlowConvertorTest.java => flow/FlowStatsResponseConvertorTest.java} (82%) rename openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/{ => flow}/flowflag/FlowFlagReactorTest.java (98%) diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/FlowService.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/FlowService.java index ab05258539..8fdab89397 100644 --- a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/FlowService.java +++ b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/FlowService.java @@ -12,12 +12,15 @@ import com.google.common.util.concurrent.Futures; import com.google.common.util.concurrent.ListenableFuture; import com.google.common.util.concurrent.SettableFuture; import java.util.ArrayList; +import java.util.Collections; import java.util.List; +import java.util.Optional; import org.opendaylight.openflowplugin.api.OFConstants; import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext; import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack; import org.opendaylight.openflowplugin.api.openflow.device.Xid; -import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.FlowConvertor; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorManager; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.data.VersionDatapathIdConvertorData; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.Flow; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowModInputBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader; @@ -39,7 +42,11 @@ final class FlowService extends AbstractSimpleService toFlowModInputs(final Flow input) { - return FlowConvertor.toFlowModInputs(input, getVersion(), getDatapathId()); + final VersionDatapathIdConvertorData data = new VersionDatapathIdConvertorData(getVersion()); + data.setDatapathId(getDatapathId()); + + final Optional> flowModInputBuilders = ConvertorManager.getInstance().convert(input, data); + return flowModInputBuilders.orElse(Collections.emptyList()); } ListenableFuture> processFlowModInputBuilders(final List ofFlowModInputs) { diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/SinglePurposeMultipartReplyTranslator.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/SinglePurposeMultipartReplyTranslator.java index 9447fe04f1..676badbd51 100644 --- a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/SinglePurposeMultipartReplyTranslator.java +++ b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/SinglePurposeMultipartReplyTranslator.java @@ -14,13 +14,14 @@ import java.util.List; import java.util.Optional; import org.opendaylight.openflowplugin.api.openflow.md.util.OpenflowVersion; import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorManager; -import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.FlowStatsResponseConvertor; 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.openflowplugin.openflow.md.util.InventoryDataServiceUtil; 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.AggregateFlowStatisticsUpdateBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.FlowsStatisticsUpdateBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.flow.and.statistics.map.list.FlowAndStatisticsMapList; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.FlowTableStatisticsUpdateBuilder; 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; @@ -110,8 +111,6 @@ public class SinglePurposeMultipartReplyTranslator { protected static final Logger logger = LoggerFactory .getLogger(SinglePurposeMultipartReplyTranslator.class); - private static FlowStatsResponseConvertor flowStatsConvertor = new FlowStatsResponseConvertor(); - public List translate(final BigInteger datapathId, final short version, final OfHeader msg) { List listDataObject = new ArrayList<>(); @@ -120,9 +119,11 @@ public class SinglePurposeMultipartReplyTranslator { MultipartReplyMessage mpReply = (MultipartReplyMessage) msg; OpenflowVersion ofVersion = OpenflowVersion.get(version); NodeId node = nodeIdFromDatapathId(datapathId); + VersionDatapathIdConvertorData versionDatapathIdConvertorData = new VersionDatapathIdConvertorData(version); + versionDatapathIdConvertorData.setDatapathId(datapathId); VersionConvertorData simpleConvertorData = new VersionConvertorData(version); - translateFlow(listDataObject, mpReply, node, ofVersion, datapathId); + translateFlow(listDataObject, mpReply, node, versionDatapathIdConvertorData); translateAggregate(listDataObject, mpReply, node); translatePortStats(listDataObject, mpReply, node, ofVersion, datapathId); translateGroup(listDataObject, mpReply, node); @@ -140,9 +141,7 @@ public class SinglePurposeMultipartReplyTranslator { private static void translateFlow(final List listDataObject, final MultipartReplyMessage mpReply, - final NodeId node, - final OpenflowVersion ofVersion, - final BigInteger datapathId) { + final NodeId node, VersionDatapathIdConvertorData versionDatapathIdConvertorData) { if (!MultipartType.OFPMPFLOW.equals(mpReply.getType())) { return; } @@ -153,7 +152,10 @@ public class SinglePurposeMultipartReplyTranslator { message.setTransactionId(generateTransactionId(mpReply.getXid())); MultipartReplyFlowCase caseBody = (MultipartReplyFlowCase) mpReply.getMultipartReplyBody(); MultipartReplyFlow replyBody = caseBody.getMultipartReplyFlow(); - message.setFlowAndStatisticsMapList(flowStatsConvertor.toSALFlowStatsList(replyBody.getFlowStats(), datapathId, ofVersion)); + final Optional> flowAndStatisticsMapLists = + ConvertorManager.getInstance().convert(replyBody.getFlowStats(), versionDatapathIdConvertorData); + + message.setFlowAndStatisticsMapList(flowAndStatisticsMapLists.orElse(Collections.emptyList())); listDataObject.add(message.build()); } diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/compatibility/FlowStatisticsToNotificationTransformer.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/compatibility/FlowStatisticsToNotificationTransformer.java index c3e2a91c82..27a7c6039c 100644 --- a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/compatibility/FlowStatisticsToNotificationTransformer.java +++ b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/compatibility/FlowStatisticsToNotificationTransformer.java @@ -11,9 +11,11 @@ package org.opendaylight.openflowplugin.impl.statistics.services.compatibility; import com.google.common.base.Preconditions; import java.util.ArrayList; import java.util.List; +import java.util.Optional; import org.opendaylight.openflowplugin.api.openflow.device.DeviceInfo; import org.opendaylight.openflowplugin.api.openflow.md.util.OpenflowVersion; -import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.FlowStatsResponseConvertor; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorManager; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.data.VersionDatapathIdConvertorData; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.FlowsStatisticsUpdate; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.FlowsStatisticsUpdateBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.flow.and.statistics.map.list.FlowAndStatisticsMapList; @@ -27,9 +29,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731 * pulled out flow stats to notification transformation */ public class FlowStatisticsToNotificationTransformer { - - private static FlowStatsResponseConvertor flowStatsConvertor = new FlowStatsResponseConvertor(); - /** * @param mpResult raw multipart response from device * @param deviceInfo device state @@ -41,6 +40,8 @@ public class FlowStatisticsToNotificationTransformer { final DeviceInfo deviceInfo, final OpenflowVersion ofVersion, final TransactionId emulatedTxId) { + final VersionDatapathIdConvertorData data = new VersionDatapathIdConvertorData(ofVersion.getVersion()); + data.setDatapathId(deviceInfo.getDatapathId()); final FlowsStatisticsUpdateBuilder notification = new FlowsStatisticsUpdateBuilder(); final List statsList = new ArrayList<>(); notification.setId(deviceInfo.getNodeId()); @@ -53,11 +54,13 @@ public class FlowStatisticsToNotificationTransformer { MultipartReplyFlowCase caseBody = (MultipartReplyFlowCase) mpRawReply.getMultipartReplyBody(); MultipartReplyFlow replyBody = caseBody.getMultipartReplyFlow(); - List outStatsItem = flowStatsConvertor.toSALFlowStatsList( - replyBody.getFlowStats(), - deviceInfo.getDatapathId(), - ofVersion); - statsList.addAll(outStatsItem); + final Optional> outStatsItem = + ConvertorManager.getInstance().convert(replyBody.getFlowStats(), data); + + + if (outStatsItem.isPresent()) { + statsList.addAll(outStatsItem.get()); + } } return notification.build(); diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/FlowDirectStatisticsService.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/FlowDirectStatisticsService.java index e30988e1aa..06fc3c123e 100644 --- a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/FlowDirectStatisticsService.java +++ b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/FlowDirectStatisticsService.java @@ -10,13 +10,15 @@ package org.opendaylight.openflowplugin.impl.statistics.services.direct; import java.util.ArrayList; import java.util.List; +import java.util.Optional; import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; import org.opendaylight.openflowplugin.api.OFConstants; import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext; import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack; import org.opendaylight.openflowplugin.api.openflow.registry.flow.FlowRegistryKey; import org.opendaylight.openflowplugin.impl.registry.flow.FlowRegistryKeyFactory; -import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.FlowStatsResponseConvertor; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorManager; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.data.VersionDatapathIdConvertorData; import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.match.MatchReactor; import org.opendaylight.yang.gen.v1.urn.opendaylight.direct.statistics.rev160511.GetFlowStatisticsInput; import org.opendaylight.yang.gen.v1.urn.opendaylight.direct.statistics.rev160511.GetFlowStatisticsOutput; @@ -47,8 +49,6 @@ import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; * The Flow direct statistics service. */ public class FlowDirectStatisticsService extends AbstractDirectStatisticsService { - private final FlowStatsResponseConvertor flowStatsConvertor = new FlowStatsResponseConvertor(); - /** * Instantiates a new Flow direct statistics service. * @@ -103,22 +103,26 @@ public class FlowDirectStatisticsService extends AbstractDirectStatisticsService @Override protected GetFlowStatisticsOutput buildReply(List input, boolean success) { final List statsList = new ArrayList<>(); + final VersionDatapathIdConvertorData data = new VersionDatapathIdConvertorData(getVersion()); + data.setDatapathId(getDatapathId()); if (success) { for (final MultipartReply mpReply : input) { final MultipartReplyFlowCase caseBody = (MultipartReplyFlowCase) mpReply.getMultipartReplyBody(); final MultipartReplyFlow replyBody = caseBody.getMultipartReplyFlow(); - - final List statsListPart = flowStatsConvertor.toSALFlowStatsList(replyBody.getFlowStats(), getDatapathId(), getOfVersion()); - - for (final FlowAndStatisticsMapList part : statsListPart) { - final org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.FlowId flowId = - new org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.FlowId(generateFlowId(part).getValue()); - - statsList.add(new FlowAndStatisticsMapListBuilder(part) - .setKey(new FlowAndStatisticsMapListKey(flowId)) - .setFlowId(flowId) - .build()); + final Optional> statsListPart = ConvertorManager.getInstance().convert( + replyBody.getFlowStats(), data); + + if (statsListPart.isPresent()) { + for (final FlowAndStatisticsMapList part : statsListPart.get()) { + final org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.FlowId flowId = + new org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.FlowId(generateFlowId(part).getValue()); + + statsList.add(new FlowAndStatisticsMapListBuilder(part) + .setKey(new FlowAndStatisticsMapListKey(flowId)) + .setFlowId(flowId) + .build()); + } } } } diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/OFRpcTaskFactory.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/OFRpcTaskFactory.java index a7446eca96..b2f69d32fe 100644 --- a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/OFRpcTaskFactory.java +++ b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/OFRpcTaskFactory.java @@ -29,7 +29,6 @@ import org.opendaylight.openflowplugin.api.openflow.md.core.SwitchConnectionDist import org.opendaylight.openflowplugin.api.openflow.md.core.sal.NotificationComposer; import org.opendaylight.openflowplugin.api.openflow.md.util.OpenflowVersion; import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorManager; -import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.FlowConvertor; import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.GroupConvertor; import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.MeterConvertor; import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.PortConvertor; @@ -219,12 +218,16 @@ public abstract class OFRpcTaskFactory { @Override public ListenableFuture> call() { ListenableFuture> result = SettableFuture.create(); + final VersionDatapathIdConvertorData data = new VersionDatapathIdConvertorData(getVersion()); + data.setDatapathId(getSession().getFeatures().getDatapathId()); // Convert the AddFlowInput to FlowModInput - List ofFlowModInputs = FlowConvertor.toFlowModInputs(getInput(), - getVersion(), getSession().getFeatures().getDatapathId()); - LOG.debug("Number of flows to push to switch: {}", ofFlowModInputs.size()); - result = chainFlowMods(ofFlowModInputs, 0, getTaskContext(), getCookie()); + final java.util.Optional> ofFlowModInputs = + ConvertorManager.getInstance().convert(getInput(), data); + + final List flowModInputs = ofFlowModInputs.orElse(Collections.emptyList()); + LOG.debug("Number of flows to push to switch: {}", flowModInputs.size()); + result = chainFlowMods(flowModInputs, 0, getTaskContext(), getCookie()); result = OFRpcTaskUtil.chainFutureBarrier(this, result); OFRpcTaskUtil.hookFutureNotification(this, result, getRpcNotificationProviderService(), @@ -351,23 +354,27 @@ public abstract class OFRpcTaskFactory { Short version = getVersion(); List allFlowMods = new ArrayList<>(); - List ofFlowModInputs; + java.util.Optional> ofFlowModInputs; + final VersionDatapathIdConvertorData data = new VersionDatapathIdConvertorData(version); + data.setDatapathId(getSession().getFeatures().getDatapathId()); if (!FlowCreatorUtil.canModifyFlow(original, updated, version)) { // We would need to remove original and add updated. //remove flow RemoveFlowInputBuilder removeflow = new RemoveFlowInputBuilder(original); - List ofFlowRemoveInput = FlowConvertor.toFlowModInputs(removeflow.build(), - version, getSession().getFeatures().getDatapathId()); - // remove flow should be the first - allFlowMods.addAll(ofFlowRemoveInput); + java.util.Optional> ofFlowRemoveInput = + ConvertorManager.getInstance().convert(removeflow.build(), data); + + if (ofFlowRemoveInput.isPresent()) { + // remove flow should be the first + allFlowMods.addAll(ofFlowRemoveInput.get()); + } + AddFlowInputBuilder addFlowInputBuilder = new AddFlowInputBuilder(updated); - ofFlowModInputs = FlowConvertor.toFlowModInputs(addFlowInputBuilder.build(), - version, getSession().getFeatures().getDatapathId()); + ofFlowModInputs = ConvertorManager.getInstance().convert(addFlowInputBuilder.build(), data); } else { - ofFlowModInputs = FlowConvertor.toFlowModInputs(updated, - version, getSession().getFeatures().getDatapathId()); + ofFlowModInputs = ConvertorManager.getInstance().convert(updated, data); } //deleting flow hash value from operational DS @@ -403,7 +410,10 @@ public abstract class OFRpcTaskFactory { } - allFlowMods.addAll(ofFlowModInputs); + if (ofFlowModInputs.isPresent()) { + allFlowMods.addAll(ofFlowModInputs.get()); + } + LOG.debug("Number of flows to push to switch: {}", allFlowMods.size()); result = chainFlowMods(allFlowMods, 0, getTaskContext(), getCookie()); @@ -726,12 +736,14 @@ public abstract class OFRpcTaskFactory { @Override public ListenableFuture> call() { ListenableFuture> result = SettableFuture.create(); + final VersionDatapathIdConvertorData data = new VersionDatapathIdConvertorData(getVersion()); + data.setDatapathId(getSession().getFeatures().getDatapathId()); // Convert the AddFlowInput to FlowModInput - List ofFlowModInputs = FlowConvertor.toFlowModInputs(getInput(), - getVersion(), getSession().getFeatures().getDatapathId()); + final java.util.Optional> ofFlowModInputs = + ConvertorManager.getInstance().convert(getInput(), data); - result = chainFlowMods(ofFlowModInputs, 0, getTaskContext(), getCookie()); + result = chainFlowMods(ofFlowModInputs.orElse(Collections.emptyList()), 0, getTaskContext(), getCookie()); result = OFRpcTaskUtil.chainFutureBarrier(this, result); OFRpcTaskUtil.hookFutureNotification(this, result, diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/ConvertorManager.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/ConvertorManager.java index d8cf176b20..aea5ec7ec8 100644 --- a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/ConvertorManager.java +++ b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/ConvertorManager.java @@ -21,6 +21,9 @@ import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.Act import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.Convertor; import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.ConvertorData; import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.ParametrizedConvertor; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.flow.FlowConvertor; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.flow.FlowInstructionResponseConvertor; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.flow.FlowStatsResponseConvertor; import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.match.MatchResponseConvertor; import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.match.MatchV10ResponseConvertor; import org.slf4j.Logger; @@ -51,6 +54,9 @@ public class ConvertorManager { INSTANCE.registerConvertor(new GroupDescStatsResponseConvertor()); INSTANCE.registerConvertor(new GroupStatsResponseConvertor()); INSTANCE.registerConvertor(new PacketOutConvertor()); + INSTANCE.registerConvertor(new FlowConvertor()); + INSTANCE.registerConvertor(new FlowInstructionResponseConvertor()); + INSTANCE.registerConvertor(new FlowStatsResponseConvertor()); } // Actual convertor keys diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/FlowStatsResponseConvertor.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/FlowStatsResponseConvertor.java deleted file mode 100644 index 83901dc907..0000000000 --- a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/FlowStatsResponseConvertor.java +++ /dev/null @@ -1,130 +0,0 @@ -/* - * Copyright (c) 2013, 2015 IBM Corporation and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * 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; - -import java.math.BigInteger; -import java.util.ArrayList; -import java.util.List; -import java.util.Optional; -import org.opendaylight.openflowplugin.api.OFConstants; -import org.opendaylight.openflowplugin.api.openflow.md.util.OpenflowVersion; -import org.opendaylight.openflowplugin.extension.api.AugmentTuple; -import org.opendaylight.openflowplugin.extension.api.path.MatchPath; -import org.opendaylight.openflowplugin.openflow.md.core.extension.MatchExtensionHelper; -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.openflowplugin.openflow.md.core.sal.convertor.data.VersionDatapathIdConvertorData; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.flow.and.statistics.map.list.FlowAndStatisticsMapList; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.flow.and.statistics.map.list.FlowAndStatisticsMapListBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowCookie; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowModFlags; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Match; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder; -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; - -/** - * Class is an utility class for converting flow related statistics messages coming from openflow - * switch to MD-SAL messages. - * @author avishnoi@in.ibm.com - * - */ -public class FlowStatsResponseConvertor { - - /** - * Method returns the list of MD-SAL format flow statistics, converted flow Openflow - * specific flow statistics. - * @param allFlowStats all flow stats - * @param datapathid datapath id - * @param ofVersion openflow version - * @return list of flow and statistics mapping - */ - public List toSALFlowStatsList(List allFlowStats, BigInteger datapathid, OpenflowVersion ofVersion){ - - List convertedSALFlowStats = new ArrayList(); - - for(FlowStats flowStats : allFlowStats){ - convertedSALFlowStats.add(toSALFlowStats(flowStats, datapathid, ofVersion)); - } - - return convertedSALFlowStats; - } - - /** - * Method convert Openflow switch specific flow statistics to the MD-SAL format - * flow statistics. - * @param flowStats flow statis - * @param datapathid datapath id - * @param ofVersion openflow version - * @return flow and statistics map - */ - public FlowAndStatisticsMapList toSALFlowStats(FlowStats flowStats, BigInteger datapathid, OpenflowVersion ofVersion){ - FlowAndStatisticsMapListBuilder salFlowStatsBuilder = new FlowAndStatisticsMapListBuilder(); - salFlowStatsBuilder.setByteCount(new Counter64(flowStats.getByteCount())); - if(flowStats.getCookie() != null) { - salFlowStatsBuilder.setCookie(new FlowCookie(flowStats.getCookie())); - } - DurationBuilder time = new DurationBuilder(); - time.setSecond(new Counter32(flowStats.getDurationSec())); - time.setNanosecond(new Counter32(flowStats.getDurationNsec())); - salFlowStatsBuilder.setDuration(time.build()); - - salFlowStatsBuilder.setHardTimeout(flowStats.getHardTimeout()); - salFlowStatsBuilder.setIdleTimeout(flowStats.getIdleTimeout()); - salFlowStatsBuilder.setPacketCount(new Counter64(flowStats.getPacketCount())); - salFlowStatsBuilder.setPriority(flowStats.getPriority()); - salFlowStatsBuilder.setTableId(flowStats.getTableId()); - if(flowStats.getMatchV10() != null){ - VersionDatapathIdConvertorData data = new VersionDatapathIdConvertorData(OFConstants.OFP_VERSION_1_0); - data.setDatapathId(datapathid); - - Optional matchBuilder = ConvertorManager.getInstance().convert(flowStats.getMatchV10(), data); - - if (matchBuilder.isPresent()) { - salFlowStatsBuilder.setMatch(matchBuilder.get().build()); - } - - if(flowStats.getAction() != null && flowStats.getAction().size()!=0){ - salFlowStatsBuilder.setInstructions(OFToMDSalFlowConvertor.wrapOF10ActionsToInstruction(flowStats.getAction(), ofVersion)); - } - } - if(flowStats.getMatch() != null){ - VersionDatapathIdConvertorData data = new VersionDatapathIdConvertorData(ofVersion.getVersion()); - data.setDatapathId(datapathid); - - Optional matchBuilderOptional = ConvertorManager.getInstance().convert(flowStats.getMatch(), data); - - if (matchBuilderOptional.isPresent()) { - MatchBuilder matchBuilder = matchBuilderOptional.get(); - - AugmentTuple matchExtensionWrap = - MatchExtensionHelper.processAllExtensions( - flowStats.getMatch().getMatchEntry(), ofVersion, MatchPath.FLOWSSTATISTICSUPDATE_FLOWANDSTATISTICSMAPLIST_MATCH); - - if (matchExtensionWrap != null) { - matchBuilder.addAugmentation(matchExtensionWrap.getAugmentationClass(), matchExtensionWrap.getAugmentationObject()); - } - - salFlowStatsBuilder.setMatch(matchBuilder.build()); - } - - salFlowStatsBuilder.setFlags( - new FlowModFlags(flowStats.getFlags().isOFPFFCHECKOVERLAP(), - flowStats.getFlags().isOFPFFRESETCOUNTS(), - flowStats.getFlags().isOFPFFNOPKTCOUNTS(), - flowStats.getFlags().isOFPFFNOBYTCOUNTS(), - flowStats.getFlags().isOFPFFSENDFLOWREM())); - } - if(flowStats.getInstruction()!= null){ - salFlowStatsBuilder.setInstructions(OFToMDSalFlowConvertor.toSALInstruction(flowStats.getInstruction(), ofVersion)); - } - - return salFlowStatsBuilder.build(); - } -} diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/FlowConvertor.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/flow/FlowConvertor.java similarity index 63% rename from openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/FlowConvertor.java rename to openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/flow/FlowConvertor.java index 0e8f56651e..758fc27a47 100644 --- a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/FlowConvertor.java +++ b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/flow/FlowConvertor.java @@ -1,4 +1,4 @@ -/** +/* * Copyright (c) 2013, 2015 Ericsson. and others. All rights reserved. * * This program and the accompanying materials are made available under the @@ -6,22 +6,31 @@ * and is available at http://www.eclipse.org/legal/epl-v10.html */ -package org.opendaylight.openflowplugin.openflow.md.core.sal.convertor; +package org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.flow; import com.google.common.base.MoreObjects; -import com.google.common.base.Optional; import com.google.common.base.Preconditions; import com.google.common.collect.Ordering; import java.math.BigInteger; import java.util.ArrayList; import java.util.Collections; import java.util.List; +import java.util.Optional; import org.opendaylight.openflowplugin.api.OFConstants; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorManager; import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.data.ActionConvertorData; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.ConvertorProcessor; import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.OrderComparator; -import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.flowflag.FlowFlagReactor; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.ParametrizedConvertor; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.data.VersionDatapathIdConvertorData; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.flow.cases.ApplyActionsCase; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.flow.cases.ClearActionsCase; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.flow.cases.GoToTableCase; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.flow.cases.MeterCase; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.flow.cases.WriteActionsCase; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.flow.cases.WriteMetadataCase; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.flow.flowflag.FlowFlagReactor; import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.match.MatchReactor; -import org.opendaylight.openflowplugin.openflow.md.util.ByteUtil; import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.VlanCfi; import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.PushVlanActionCase; import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.PushVlanActionCaseBuilder; @@ -39,35 +48,15 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.I import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.InstructionsBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Match; 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.ApplyActionsCase; 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.ClearActionsCase; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.GoToTableCase; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.MeterCase; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.WriteActionsCase; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.WriteMetadataCase; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.apply.actions._case.ApplyActions; 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.instruction.go.to.table._case.GoToTable; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.meter._case.Meter; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.write.actions._case.WriteActions; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.write.metadata._case.WriteMetadata; import org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanId; import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.VlanMatch; import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.VlanMatchBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.vlan.match.fields.VlanIdBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.Action; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instruction.grouping.instruction.choice.ClearActionsCaseBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instruction.grouping.instruction.choice.GotoTableCaseBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instruction.grouping.instruction.choice.MeterCaseBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instruction.grouping.instruction.choice.WriteActionsCaseBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instruction.grouping.instruction.choice.WriteMetadataCaseBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instruction.grouping.instruction.choice._goto.table._case.GotoTableBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instruction.grouping.instruction.choice.meter._case.MeterBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instruction.grouping.instruction.choice.write.actions._case.WriteActionsBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instruction.grouping.instruction.choice.write.metadata._case.WriteMetadataBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instructions.grouping.Instruction; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instructions.grouping.InstructionBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.FlowModCommand; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MatchTypeBase; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumber; @@ -75,17 +64,21 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev13 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.OxmMatchType; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntry; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowModInputBuilder; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; /** - * Utility class for converting a MD-SAL Flow into the OF flow mod + * Converts the SAL Flow to OF Flow. It checks if there is a set-vlan-id (1.0) action made on OF1.3. + * If yes its handled separately. + * + * Example usage: + *
+ * {@code
+ * VersionDatapathIdConvertorData data = new VersionDatapathIdConvertorData(version);
+ * data.setDatapathId(datapathId);
+ * Optional> ofFlow = ConvertorManager.getInstance().convert(salFlow, data);
+ * }
+ * 
*/ -public class FlowConvertor { - private static final Logger LOG = LoggerFactory.getLogger(FlowConvertor.class); - - // Default values for when things are null - private static final TableId DEFAULT_TABLE_ID = new TableId(0L); +public class FlowConvertor implements ParametrizedConvertor, VersionDatapathIdConvertorData> { /** * Default idle timeout */ @@ -98,11 +91,6 @@ public class FlowConvertor { * Default priority */ public static final Integer DEFAULT_PRIORITY = Integer.parseInt("8000", 16); - private static final Long DEFAULT_BUFFER_ID = OFConstants.OFP_NO_BUFFER; - private static final Long OFPP_ANY = Long.parseLong("ffffffff", 16); - private static final Long DEFAULT_OUT_PORT = OFPP_ANY; - private static final Long OFPG_ANY = Long.parseLong("ffffffff", 16); - private static final Long DEFAULT_OUT_GROUP = OFPG_ANY; /** * flow flag: remove */ @@ -134,14 +122,26 @@ public class FlowConvertor { /** * default match entries - empty */ - public static final List DEFAULT_MATCH_ENTRIES = new ArrayList(); - private static final Integer PUSH_VLAN = 0x8100; - - private static final Ordering INSTRUCTION_ORDERING = - Ordering.from(OrderComparator.build()); + public static final List DEFAULT_MATCH_ENTRIES = new ArrayList<>(); + // Default values for when things are null + private static final TableId DEFAULT_TABLE_ID = new TableId(0L); + private static final Long DEFAULT_BUFFER_ID = OFConstants.OFP_NO_BUFFER; + private static final Long OFPP_ANY = Long.parseLong("ffffffff", 16); + private static final Long DEFAULT_OUT_PORT = OFPP_ANY; + private static final Long OFPG_ANY = Long.parseLong("ffffffff", 16); + private static final Long DEFAULT_OUT_GROUP = OFPG_ANY; + private static final Integer PUSH_VLAN = 0x8100; + private static final Ordering INSTRUCTION_ORDERING = Ordering.from(OrderComparator.build()); private static final VlanMatch VLAN_MATCH_FALSE; private static final VlanMatch VLAN_MATCH_TRUE; + private static final ConvertorProcessor PROCESSOR = new ConvertorProcessor() + .addCase(new ApplyActionsCase()) + .addCase(new ClearActionsCase()) + .addCase(new GoToTableCase()) + .addCase(new MeterCase()) + .addCase(new WriteActionsCase()) + .addCase(new WriteMetadataCase()); static { final VlanId zeroVlan = new VlanId(0); @@ -162,28 +162,6 @@ public class FlowConvertor { VLAN_MATCH_TRUE = vlanMatchBuilder2.build(); } - private FlowConvertor() { - //hiding implicit constructor - } - - /** - * This method converts the SAL Flow to OF Flow. - * It checks if there is a set-vlan-id (1.0) action made on OF1.3. - * If yes its handled separately - * - * @param srcFlow source flow - * @param version openflow version - * @param datapathId datapath id - * @return list of flow mod build - */ - public static List toFlowModInputs(Flow srcFlow, short version, BigInteger datapathId) { - if (version >= OFConstants.OFP_VERSION_1_3 && isSetVlanIdActionCasePresent(srcFlow)) { - return handleSetVlanIdForOF13(srcFlow, version, datapathId); - } else { - return Collections.singletonList(toFlowModInput(srcFlow, version, datapathId)); - } - } - private static FlowModInputBuilder toFlowModInput(Flow flow, short version, BigInteger datapathid) { FlowModInputBuilder flowMod = new FlowModInputBuilder(); @@ -208,6 +186,7 @@ public class FlowConvertor { flowMod.setInstruction(toInstructions(flow, version, datapathid)); flowMod.setAction(getActions(version, datapathid, flow)); } + flowMod.setVersion(version); return flowMod; @@ -297,95 +276,31 @@ public class FlowConvertor { } } - private static List toInstructions( - Flow flow, - short version, BigInteger datapathid) { - List instructionsList = new ArrayList<>(); + private static List toInstructions(Flow flow, short version, BigInteger datapathid) { + final List instructionsList = new ArrayList<>(); + final ActionConvertorData data = new ActionConvertorData(version); + data.setDatapathId(datapathid); + data.setIpProtocol(FlowConvertorUtil.getIpProtocolFromFlow(flow)); + + Instructions instructions = flow.getInstructions(); - org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Instructions instructions = flow.getInstructions(); for (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.Instruction instruction : instructions .getInstruction()) { - InstructionBuilder instructionBuilder = new InstructionBuilder(); org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.Instruction curInstruction = instruction .getInstruction(); - ActionConvertorData data = new ActionConvertorData(version); - data.setDatapathId(datapathid); - if (flow.getMatch() != null && flow.getMatch().getIpMatch() != null) { - data.setIpProtocol(flow.getMatch().getIpMatch().getIpProtocol()); - } + Optional result = PROCESSOR.process(curInstruction, data); - if (curInstruction instanceof GoToTableCase) { - GoToTableCase goToTablecase = (GoToTableCase) curInstruction; - GoToTable goToTable = goToTablecase.getGoToTable(); - GotoTableCaseBuilder gotoTableCaseBuilder = new GotoTableCaseBuilder(); - GotoTableBuilder gotoTableBuilder = new GotoTableBuilder(); - gotoTableBuilder.setTableId(goToTable.getTableId()); - gotoTableCaseBuilder.setGotoTable(gotoTableBuilder.build()); - instructionBuilder.setInstructionChoice(gotoTableCaseBuilder.build()); - instructionsList.add(instructionBuilder.build()); - } else if (curInstruction instanceof WriteMetadataCase) { - WriteMetadataCase writeMetadatacase = (WriteMetadataCase) curInstruction; - WriteMetadata writeMetadata = writeMetadatacase.getWriteMetadata(); - - WriteMetadataCaseBuilder writeMetadataCaseBuilder = new WriteMetadataCaseBuilder(); - WriteMetadataBuilder writeMetadataBuilder = new WriteMetadataBuilder(); - writeMetadataBuilder.setMetadata(ByteUtil.convertBigIntegerToNBytes(writeMetadata.getMetadata(), - OFConstants.SIZE_OF_LONG_IN_BYTES)); - writeMetadataBuilder.setMetadataMask(ByteUtil.convertBigIntegerToNBytes(writeMetadata.getMetadataMask(), - OFConstants.SIZE_OF_LONG_IN_BYTES)); - writeMetadataCaseBuilder.setWriteMetadata(writeMetadataBuilder.build()); - instructionBuilder.setInstructionChoice(writeMetadataCaseBuilder.build()); - instructionsList.add(instructionBuilder.build()); - } else if (curInstruction instanceof WriteActionsCase) { - WriteActionsCase writeActionscase = (WriteActionsCase) curInstruction; - WriteActions writeActions = writeActionscase.getWriteActions(); - WriteActionsCaseBuilder writeActionsCaseBuilder = new WriteActionsCaseBuilder(); - WriteActionsBuilder writeActionsBuilder = new WriteActionsBuilder(); - - final java.util.Optional> actions = ConvertorManager.getInstance().convert( - writeActions.getAction(), data); - - writeActionsBuilder.setAction(actions.orElse(Collections.emptyList())); - writeActionsCaseBuilder.setWriteActions(writeActionsBuilder.build()); - instructionBuilder.setInstructionChoice(writeActionsCaseBuilder.build()); - instructionsList.add(instructionBuilder.build()); - } else if (curInstruction instanceof ApplyActionsCase) { - ApplyActionsCase applyActionscase = (ApplyActionsCase) curInstruction; - ApplyActions applyActions = applyActionscase.getApplyActions(); - org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instruction.grouping.instruction.choice.ApplyActionsCaseBuilder applyActionsCaseBuilder = - new org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instruction.grouping.instruction.choice.ApplyActionsCaseBuilder(); - org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instruction.grouping.instruction.choice.apply.actions._case.ApplyActionsBuilder applyActionsBuilder = - new org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instruction.grouping.instruction.choice.apply.actions._case.ApplyActionsBuilder(); - final java.util.Optional> actionList = ConvertorManager.getInstance().convert( - applyActions.getAction(), data); - - applyActionsBuilder.setAction(actionList.orElse(Collections.emptyList())); - applyActionsCaseBuilder.setApplyActions(applyActionsBuilder.build()); - instructionBuilder.setInstructionChoice(applyActionsCaseBuilder.build()); - instructionsList.add(instructionBuilder.build()); - } else if (curInstruction instanceof ClearActionsCase) { - ClearActionsCaseBuilder clearActionsCaseBuilder = new ClearActionsCaseBuilder(); - instructionBuilder.setInstructionChoice(clearActionsCaseBuilder.build()); - instructionsList.add(instructionBuilder.build()); - } else if (curInstruction instanceof MeterCase) { - MeterCase metercase = (MeterCase) curInstruction; - Meter meter = metercase.getMeter(); - MeterCaseBuilder meterCaseBuilder = new MeterCaseBuilder(); - MeterBuilder meterBuilder = new MeterBuilder(); - Long meterId = meter.getMeterId().getValue(); - meterBuilder.setMeterId(meterId); - meterCaseBuilder.setMeter(meterBuilder.build()); - instructionBuilder.setInstructionChoice(meterCaseBuilder.build()); - instructionsList.add(instructionBuilder.build()); + if (result.isPresent()) { + instructionsList.add(result.get()); } } + return instructionsList; } private static List getActions(short version, BigInteger datapathid, Flow flow) { - - org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Instructions instructions = flow.getInstructions(); + Instructions instructions = flow.getInstructions(); List sortedInstructions = INSTRUCTION_ORDERING.sortedCopy(instructions.getInstruction()); @@ -393,20 +308,18 @@ public class FlowConvertor { org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.Instruction curInstruction = instruction .getInstruction(); - if (curInstruction instanceof ApplyActionsCase) { - ApplyActionsCase applyActionscase = (ApplyActionsCase) curInstruction; + if (curInstruction instanceof org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.ApplyActionsCase) { + org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.ApplyActionsCase applyActionscase = (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.ApplyActionsCase) curInstruction; ApplyActions applyActions = applyActionscase.getApplyActions(); + final ActionConvertorData data = new ActionConvertorData(version); data.setDatapathId(datapathid); - - if (flow.getMatch() != null && flow.getMatch().getIpMatch() != null) { - data.setIpProtocol(flow.getMatch().getIpMatch().getIpProtocol()); - } - - java.util.Optional> result = ConvertorManager.getInstance().convert(applyActions.getAction(), data); + data.setIpProtocol(FlowConvertorUtil.getIpProtocolFromFlow(flow)); + Optional> result = ConvertorManager.getInstance().convert(applyActions.getAction(), data); return result.orElse(Collections.emptyList()); } } + return null; } @@ -414,14 +327,14 @@ public class FlowConvertor { private static boolean isSetVlanIdActionCasePresent(Flow flow) { // we are trying to find if there is a set-vlan-id action (OF1.0) action present in the flow. // If yes,then we would need to two flows - if (flow.getInstructions() != null) { + if (flow.getInstructions() != null && flow.getInstructions().getInstruction() != null) { for (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.Instruction instruction : flow.getInstructions().getInstruction()) { org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.Instruction curInstruction = instruction.getInstruction(); - if (curInstruction instanceof ApplyActionsCase) { - ApplyActionsCase applyActionscase = (ApplyActionsCase) curInstruction; + if (curInstruction instanceof org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.ApplyActionsCase) { + org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.ApplyActionsCase applyActionscase = (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.ApplyActionsCase) curInstruction; ApplyActions applyActions = applyActionscase.getApplyActions(); for (org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action action : applyActions.getAction()) { @@ -489,13 +402,13 @@ public class FlowConvertor { private static Optional injectMatchToFlow(Flow sourceFlow, Match match) { if (sourceFlow instanceof AddFlowInput) { - return Optional.of(new AddFlowInputBuilder(sourceFlow).setMatch(match).build()); + return Optional.of(new AddFlowInputBuilder(sourceFlow).setMatch(match).build()); } else if (sourceFlow instanceof RemoveFlowInput) { - return Optional.of(new RemoveFlowInputBuilder(sourceFlow).setMatch(match).build()); + return Optional.of(new RemoveFlowInputBuilder(sourceFlow).setMatch(match).build()); } else if (sourceFlow instanceof UpdatedFlow) { - return Optional.of(new UpdatedFlowBuilder(sourceFlow).setMatch(match).build()); + return Optional.of(new UpdatedFlowBuilder(sourceFlow).setMatch(match).build()); } else { - return Optional.absent(); + return Optional.empty(); } } @@ -506,16 +419,16 @@ public class FlowConvertor { .build(); if (sourceFlow instanceof AddFlowInput) { - return Optional.of(new AddFlowInputBuilder(sourceFlow) + return Optional.of(new AddFlowInputBuilder(sourceFlow) .setMatch(match).setInstructions(instructions).build()); } else if (sourceFlow instanceof RemoveFlowInput) { - return Optional.of(new RemoveFlowInputBuilder(sourceFlow) + return Optional.of(new RemoveFlowInputBuilder(sourceFlow) .setMatch(match).setInstructions(instructions).build()); } else if (sourceFlow instanceof UpdatedFlow) { - return Optional.of(new UpdatedFlowBuilder(sourceFlow) + return Optional.of(new UpdatedFlowBuilder(sourceFlow) .setMatch(match).setInstructions(instructions).build()); } else { - return Optional.absent(); + return Optional.empty(); } } @@ -531,22 +444,19 @@ public class FlowConvertor { org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.InstructionBuilder instructionBuilder = new org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.InstructionBuilder(); - for (int i = 0; i < srcInstructionList.size(); i++) { - org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.Instruction srcInstruction = - srcInstructionList.get(i); + for (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.Instruction srcInstruction : srcInstructionList) { org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.Instruction curSrcInstruction = srcInstruction.getInstruction(); - if (curSrcInstruction instanceof ApplyActionsCase) { - ApplyActionsCase applyActionscase = (ApplyActionsCase) curSrcInstruction; + if (curSrcInstruction instanceof org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.ApplyActionsCase) { + org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.ApplyActionsCase applyActionscase = (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.ApplyActionsCase) curSrcInstruction; ApplyActions applyActions = applyActionscase.getApplyActions(); List srcActionList = applyActions.getAction(); int offset = 0; - for (int j = 0; j < srcActionList.size(); j++) { + for (org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action actionItem : srcActionList) { // check if its a set-vlan-action. If yes, then add the injected-action - org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action actionItem = srcActionList.get(j); if (actionItem.getAction() instanceof SetVlanIdActionCase) { SetVlanIdActionCase setVlanIdActionCase = (SetVlanIdActionCase) actionItem.getAction(); @@ -560,7 +470,7 @@ public class FlowConvertor { pushVlanActionCaseBuilder.setPushVlanAction(pushVlanActionBuilder.build()); PushVlanActionCase injectedAction = pushVlanActionCaseBuilder.build(); - org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionBuilder actionBuilder = new ActionBuilder(); + ActionBuilder actionBuilder = new ActionBuilder(); actionBuilder.setAction(injectedAction) .setKey(actionItem.getKey()) .setOrder(actionItem.getOrder() + offset); @@ -571,8 +481,8 @@ public class FlowConvertor { if (offset > 0) { // we need to increment the order for all the actions added after injection - org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionBuilder actionBuilder = - new org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionBuilder(actionItem); + ActionBuilder actionBuilder = + new ActionBuilder(actionItem); actionBuilder.setOrder(actionItem.getOrder() + offset); actionItem = actionBuilder.build(); } @@ -600,4 +510,17 @@ public class FlowConvertor { return targetInstructionList; } + @Override + public Class getType() { + return Flow.class; + } + + @Override + public List convert(Flow source, VersionDatapathIdConvertorData data) { + if (data.getVersion() >= OFConstants.OFP_VERSION_1_3 && isSetVlanIdActionCasePresent(source)) { + return handleSetVlanIdForOF13(source, data.getVersion(), data.getDatapathId()); + } else { + return Collections.singletonList(toFlowModInput(source, data.getVersion(), data.getDatapathId())); + } + } } diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/flow/FlowConvertorUtil.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/flow/FlowConvertorUtil.java new file mode 100644 index 0000000000..ac765e1158 --- /dev/null +++ b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/flow/FlowConvertorUtil.java @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * 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; +import java.util.List; +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.flow.types.rev131026.Flow; + +/** + * Flow related utils + */ +public abstract class FlowConvertorUtil { + + /** + * Method wrapping all the actions org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action + * in org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action, to set appropriate keys + * for actions. + * + * @param actionList the action list + * @return the list + */ + public static List wrapActionList(List actionList) { + List actions = new ArrayList<>(); + + int actionKey = 0; + for (org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action action : actionList) { + ActionBuilder wrappedAction = new ActionBuilder(); + wrappedAction.setAction(action); + wrappedAction.setKey(new ActionKey(actionKey)); + wrappedAction.setOrder(actionKey); + actions.add(wrappedAction.build()); + actionKey++; + } + + return actions; + } + + /** + * Safely gets ip protocol from flow. + * + * @param flow the flow + * @return the ip protocol from flow + */ + public static Short getIpProtocolFromFlow(Flow flow) { + Short ipProtocol = null; + + if (flow.getMatch() != null && flow.getMatch().getIpMatch() != null) { + ipProtocol = flow.getMatch().getIpMatch().getIpProtocol(); + } + + return ipProtocol; + } +} diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/OFToMDSalFlowConvertor.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/flow/FlowInstructionResponseConvertor.java similarity index 64% rename from openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/OFToMDSalFlowConvertor.java rename to openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/flow/FlowInstructionResponseConvertor.java index 35480d7dcf..9a160f69d0 100644 --- a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/OFToMDSalFlowConvertor.java +++ b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/flow/FlowInstructionResponseConvertor.java @@ -6,7 +6,7 @@ * and is available at http://www.eclipse.org/legal/epl-v10.html */ -package org.opendaylight.openflowplugin.openflow.md.core.sal.convertor; +package org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.flow; import java.math.BigInteger; import java.util.ArrayList; @@ -14,12 +14,12 @@ import java.util.Collections; import java.util.List; import java.util.Optional; import org.opendaylight.openflowplugin.api.OFConstants; -import org.opendaylight.openflowplugin.api.openflow.md.util.OpenflowVersion; import org.opendaylight.openflowplugin.extension.api.path.ActionPath; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorManager; import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.data.ActionResponseConvertorData; -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.openflowplugin.openflow.md.core.sal.convertor.common.ParametrizedConvertor; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.data.VersionConvertorData; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Instructions; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.InstructionsBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.ApplyActionsCaseBuilder; @@ -42,52 +42,55 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instruction.grouping.instruction.choice.MeterCase; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instruction.grouping.instruction.choice.WriteActionsCase; -public final class OFToMDSalFlowConvertor { - - private OFToMDSalFlowConvertor() { - // hiding implicite constructor +/** + * Converts Openflow 1.3+ specific instructions to MD-SAL format flow instruction + * + * Example usage: + *
+ * {@code
+ * VersionConvertorData data = new VersionConvertorData(version);
+ * Optional salFlowInstruction = ConvertorManager.getInstance().convert(ofFlowInstructions, data);
+ * }
+ * 
+ */ +public final class FlowInstructionResponseConvertor implements ParametrizedConvertor< + List, + Instructions, + VersionConvertorData> { + + @Override + public Class getType() { + return org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instructions.grouping.Instruction.class; } - /** - * Method convert Openflow 1.3+ specific instructions to MD-SAL format - * flow instruction - * - * @param instructions instructions - * @param ofVersion current ofp version - * @return instruction converted to SAL instruction - */ - public static Instructions toSALInstruction( - List instructions, OpenflowVersion ofVersion) { - + @Override + public Instructions convert(List source, VersionConvertorData data) { InstructionsBuilder instructionsBuilder = new InstructionsBuilder(); - List salInstructionList = new ArrayList(); + List salInstructionList = new ArrayList<>(); int instructionTreeNodekey = 0; org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.Instruction salInstruction; - for (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instructions.grouping.Instruction switchInst : instructions) { - if (switchInst.getInstructionChoice() instanceof ApplyActionsCase) { + for (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instructions.grouping. + Instruction switchInst : source) { + if (switchInst.getInstructionChoice() instanceof ApplyActionsCase) { ApplyActionsCase actionsInstruction = ((ApplyActionsCase) switchInst.getInstructionChoice()); ApplyActionsCaseBuilder applyActionsCaseBuilder = new ApplyActionsCaseBuilder(); ApplyActionsBuilder applyActionsBuilder = new ApplyActionsBuilder(); - final ActionResponseConvertorData actionResponseConvertorData = new ActionResponseConvertorData(ofVersion.getVersion()); + final ActionResponseConvertorData actionResponseConvertorData = new ActionResponseConvertorData(data.getVersion()); actionResponseConvertorData.setActionPath(ActionPath.FLOWSSTATISTICSUPDATE_FLOWANDSTATISTICSMAPLIST_INSTRUCTIONS_INSTRUCTION_INSTRUCTION_APPLYACTIONSCASE_APPLYACTIONS_ACTION_ACTION); - final Optional> actions = ConvertorManager.getInstance().convert( + final Optional> actions = ConvertorManager.getInstance().convert( actionsInstruction.getApplyActions().getAction(), actionResponseConvertorData); - applyActionsBuilder.setAction(wrapActionList(actions.orElse(Collections.emptyList()))); + applyActionsBuilder.setAction(FlowConvertorUtil.wrapActionList(actions.orElse(Collections.emptyList()))); applyActionsCaseBuilder.setApplyActions(applyActionsBuilder.build()); salInstruction = applyActionsCaseBuilder.build(); } else if (switchInst.getInstructionChoice() instanceof org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instruction.grouping.instruction.choice.ClearActionsCase) { - - org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instruction.grouping.instruction.choice.ClearActionsCase clearActionsCase = - ((org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instruction.grouping.instruction.choice.ClearActionsCase) switchInst.getInstructionChoice()); ClearActionsCaseBuilder clearActionsCaseBuilder = new ClearActionsCaseBuilder(); salInstruction = clearActionsCaseBuilder.build(); } else if (switchInst.getInstructionChoice() instanceof GotoTableCase) { - GotoTableCase gotoTableCase = ((GotoTableCase) switchInst.getInstructionChoice()); GoToTableCaseBuilder goToTableCaseBuilder = new GoToTableCaseBuilder(); @@ -97,10 +100,8 @@ public final class OFToMDSalFlowConvertor { salInstruction = goToTableCaseBuilder.build(); } else if (switchInst.getInstructionChoice() instanceof MeterCase) { - MeterCase meterIdInstruction = ((MeterCase) switchInst.getInstructionChoice()); - MeterCaseBuilder meterCaseBuilder = new MeterCaseBuilder(); MeterBuilder meterBuilder = new MeterBuilder(); meterBuilder.setMeterId(new MeterId(meterIdInstruction.getMeter().getMeterId())); @@ -108,24 +109,20 @@ public final class OFToMDSalFlowConvertor { salInstruction = meterCaseBuilder.build(); } else if (switchInst.getInstructionChoice() instanceof WriteActionsCase) { - WriteActionsCase writeActionsCase = ((WriteActionsCase) switchInst.getInstructionChoice()); - WriteActionsCaseBuilder writeActionsCaseBuilder = new WriteActionsCaseBuilder(); WriteActionsBuilder writeActionsBuilder = new WriteActionsBuilder(); - final ActionResponseConvertorData actionResponseConvertorData = new ActionResponseConvertorData(ofVersion.getVersion()); + final ActionResponseConvertorData actionResponseConvertorData = new ActionResponseConvertorData(data.getVersion()); actionResponseConvertorData.setActionPath(ActionPath.FLOWSSTATISTICSUPDATE_FLOWANDSTATISTICSMAPLIST_INSTRUCTIONS_INSTRUCTION_INSTRUCTION_WRITEACTIONSCASE_WRITEACTIONS_ACTION_ACTION); - final Optional> actions = ConvertorManager.getInstance().convert( + final Optional> actions = ConvertorManager.getInstance().convert( writeActionsCase.getWriteActions().getAction(), actionResponseConvertorData); - writeActionsBuilder.setAction(wrapActionList(actions.orElse(Collections.emptyList()))); + writeActionsBuilder.setAction(FlowConvertorUtil.wrapActionList(actions.orElse(Collections.emptyList()))); writeActionsCaseBuilder.setWriteActions(writeActionsBuilder.build()); - salInstruction = writeActionsCaseBuilder.build(); } else if (switchInst.getInstructionChoice() instanceof org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instruction.grouping.instruction.choice.WriteMetadataCase) { - org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instruction.grouping.instruction.choice.WriteMetadataCase writeMetadataCase = ((org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instruction.grouping.instruction.choice.WriteMetadataCase) switchInst.getInstructionChoice()); WriteMetadataCaseBuilder writeMetadataCaseBuilder = new WriteMetadataCaseBuilder(); @@ -146,65 +143,8 @@ public final class OFToMDSalFlowConvertor { salInstructionList.add(instBuilder.build()); } - instructionsBuilder.setInstruction(salInstructionList); - return instructionsBuilder.build(); - } - - /* - * Method wrapping all the actions org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action - * in org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action, to set appropriate keys - * for actions. - */ - private static List wrapActionList(List actionList) { - List actions = new ArrayList<>(); - - int actionKey = 0; - for (org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action action : actionList) { - ActionBuilder wrappedAction = new ActionBuilder(); - wrappedAction.setAction(action); - wrappedAction.setKey(new ActionKey(actionKey)); - wrappedAction.setOrder(actionKey); - actions.add(wrappedAction.build()); - actionKey++; - } - - return actions; - } - - /** - * Method wraps openflow 1.0 actions list to Apply Action Instructions - * - * @param ofVersion current ofp version - * @param actionsList list of action - * @return OF10 actions as an instructions - */ - - public static Instructions wrapOF10ActionsToInstruction( - List actionsList, OpenflowVersion ofVersion) { - InstructionsBuilder instructionsBuilder = new InstructionsBuilder(); - - List salInstructionList = new ArrayList(); - - ApplyActionsCaseBuilder applyActionsCaseBuilder = new ApplyActionsCaseBuilder(); - ApplyActionsBuilder applyActionsBuilder = new ApplyActionsBuilder(); - - final ActionResponseConvertorData actionResponseConvertorData = new ActionResponseConvertorData(ofVersion.getVersion()); - actionResponseConvertorData.setActionPath(ActionPath.FLOWSSTATISTICSUPDATE_FLOWANDSTATISTICSMAPLIST_INSTRUCTIONS_INSTRUCTION_INSTRUCTION_WRITEACTIONSCASE_WRITEACTIONS_ACTION_ACTION); - - final Optional> actions = ConvertorManager.getInstance().convert( - actionsList, actionResponseConvertorData); - - applyActionsBuilder.setAction(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(); } - } 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 new file mode 100644 index 0000000000..7da1a33b30 --- /dev/null +++ b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/flow/FlowStatsResponseConvertor.java @@ -0,0 +1,174 @@ +/* + * Copyright (c) 2013, 2015 IBM Corporation and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * 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 com.google.common.annotations.VisibleForTesting; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Optional; +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.ConvertorManager; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.data.ActionResponseConvertorData; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.ParametrizedConvertor; +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; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.flow.and.statistics.map.list.FlowAndStatisticsMapListBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowCookie; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowModFlags; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Instructions; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.InstructionsBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Match; +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.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; + +/** + * Converts flow related statistics messages coming from openflow switch to MD-SAL messages. + * + * Example usage: + *
+ * {@code
+ * VersionDatapathIdConvertorData data = new VersionDatapathIdConvertorData(version);
+ * data.setDatapathId(datapathId);
+ * Optional> salFlowStats = ConvertorManager.getInstance().convert(ofFlowStats, data);
+ * }
+ * 
+ */ +public class FlowStatsResponseConvertor implements ParametrizedConvertor, List, VersionDatapathIdConvertorData> { + + /** + * Method wraps openflow 1.0 actions list to Apply Action Instructions + * + * @param actionsList list of action + * @return OF10 actions as an instructions + */ + @VisibleForTesting + static Instructions wrapOF10ActionsToInstruction(List actionsList, final short version) { + 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<>(); + + ApplyActionsCaseBuilder applyActionsCaseBuilder = new ApplyActionsCaseBuilder(); + ApplyActionsBuilder applyActionsBuilder = new ApplyActionsBuilder(); + + final Optional> actions = ConvertorManager.getInstance().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(); + } + + @Override + public Class getType() { + return FlowStats.class; + } + + @Override + public List convert(List source, VersionDatapathIdConvertorData data) { + final List result = new ArrayList<>(); + + for (FlowStats flowStats : source) { + // Convert Openflow switch specific flow statistics to the MD-SAL format flow statistics + FlowAndStatisticsMapListBuilder salFlowStatsBuilder = new FlowAndStatisticsMapListBuilder(); + salFlowStatsBuilder.setByteCount(new Counter64(flowStats.getByteCount())); + + if (flowStats.getCookie() != null) { + salFlowStatsBuilder.setCookie(new FlowCookie(flowStats.getCookie())); + } + + DurationBuilder time = new DurationBuilder(); + time.setSecond(new Counter32(flowStats.getDurationSec())); + time.setNanosecond(new Counter32(flowStats.getDurationNsec())); + salFlowStatsBuilder.setDuration(time.build()); + + salFlowStatsBuilder.setHardTimeout(flowStats.getHardTimeout()); + salFlowStatsBuilder.setIdleTimeout(flowStats.getIdleTimeout()); + salFlowStatsBuilder.setPacketCount(new Counter64(flowStats.getPacketCount())); + salFlowStatsBuilder.setPriority(flowStats.getPriority()); + salFlowStatsBuilder.setTableId(flowStats.getTableId()); + + if (flowStats.getMatchV10() != null) { + final Optional matchBuilderOptional = ConvertorManager.getInstance().convert(flowStats.getMatchV10(), data); + + if (matchBuilderOptional.isPresent()) { + salFlowStatsBuilder.setMatch(matchBuilderOptional.get().build()); + } + + if (flowStats.getAction() != null && flowStats.getAction().size() != 0) { + salFlowStatsBuilder.setInstructions(wrapOF10ActionsToInstruction(flowStats.getAction(), data.getVersion())); + } + } + + if (flowStats.getMatch() != null) { + final Optional matchBuilderOptional = ConvertorManager.getInstance().convert(flowStats.getMatch(), data); + + if (matchBuilderOptional.isPresent()) { + final MatchBuilder matchBuilder = matchBuilderOptional.get(); + + final AugmentTuple matchExtensionWrap = + MatchExtensionHelper.processAllExtensions( + flowStats.getMatch().getMatchEntry(), + OpenflowVersion.get(data.getVersion()), + MatchPath.FLOWSSTATISTICSUPDATE_FLOWANDSTATISTICSMAPLIST_MATCH); + + if (matchExtensionWrap != null) { + matchBuilder.addAugmentation(matchExtensionWrap.getAugmentationClass(), matchExtensionWrap.getAugmentationObject()); + } + + salFlowStatsBuilder.setMatch(matchBuilder.build()); + } + + + salFlowStatsBuilder.setFlags( + new FlowModFlags(flowStats.getFlags().isOFPFFCHECKOVERLAP(), + flowStats.getFlags().isOFPFFRESETCOUNTS(), + flowStats.getFlags().isOFPFFNOPKTCOUNTS(), + flowStats.getFlags().isOFPFFNOBYTCOUNTS(), + flowStats.getFlags().isOFPFFSENDFLOWREM())); + } + + if (flowStats.getInstruction() != null) { + final VersionConvertorData simpleConvertorData = new VersionConvertorData(data.getVersion()); + final Optional instructions = ConvertorManager.getInstance().convert( + flowStats.getInstruction(), simpleConvertorData); + + salFlowStatsBuilder.setInstructions(instructions.orElse(new InstructionsBuilder() + .setInstruction(Collections.emptyList()).build())); + } + + result.add(salFlowStatsBuilder.build()); + } + + return result; + } +} diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/flow/cases/ApplyActionsCase.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/flow/cases/ApplyActionsCase.java new file mode 100644 index 0000000000..2ed5d56d95 --- /dev/null +++ b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/flow/cases/ApplyActionsCase.java @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * 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.cases; + +import java.util.Collections; +import java.util.List; +import java.util.Optional; +import javax.annotation.Nonnull; +import org.opendaylight.openflowplugin.api.OFConstants; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorManager; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.data.ActionConvertorData; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.ConvertorCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.apply.actions._case.ApplyActions; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.Action; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instruction.grouping.instruction.choice.ApplyActionsCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instruction.grouping.instruction.choice.apply.actions._case.ApplyActionsBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instructions.grouping.Instruction; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instructions.grouping.InstructionBuilder; + +public class ApplyActionsCase extends ConvertorCase { + public ApplyActionsCase() { + super(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.ApplyActionsCase.class, true, OFConstants.OFP_VERSION_1_0, OFConstants.OFP_VERSION_1_3); + } + + @Override + public Optional process(final @Nonnull org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.ApplyActionsCase source, final ActionConvertorData data) { + ApplyActions applyActions = source.getApplyActions(); + ApplyActionsCaseBuilder applyActionsCaseBuilder = new ApplyActionsCaseBuilder(); + ApplyActionsBuilder applyActionsBuilder = new ApplyActionsBuilder(); + + final Optional> actionList = ConvertorManager.getInstance().convert( + applyActions.getAction(), data); + + applyActionsBuilder.setAction(actionList.orElse(Collections.emptyList())); + applyActionsCaseBuilder.setApplyActions(applyActionsBuilder.build()); + InstructionBuilder instructionBuilder = new InstructionBuilder(); + instructionBuilder.setInstructionChoice(applyActionsCaseBuilder.build()); + return Optional.of(instructionBuilder.build()); + } +} diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/flow/cases/ClearActionsCase.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/flow/cases/ClearActionsCase.java new file mode 100644 index 0000000000..0aa8bd610a --- /dev/null +++ b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/flow/cases/ClearActionsCase.java @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * 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.cases; + +import java.util.Optional; +import javax.annotation.Nonnull; +import org.opendaylight.openflowplugin.api.OFConstants; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.data.ActionConvertorData; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.ConvertorCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instruction.grouping.instruction.choice.ClearActionsCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instructions.grouping.Instruction; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instructions.grouping.InstructionBuilder; + +public class ClearActionsCase extends ConvertorCase { + public ClearActionsCase() { + super(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.ClearActionsCase.class, true, OFConstants.OFP_VERSION_1_0, OFConstants.OFP_VERSION_1_3); + } + + @Override + public Optional process(final @Nonnull org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.ClearActionsCase source, final ActionConvertorData data) { + ClearActionsCaseBuilder clearActionsCaseBuilder = new ClearActionsCaseBuilder(); + InstructionBuilder instructionBuilder = new InstructionBuilder(); + instructionBuilder.setInstructionChoice(clearActionsCaseBuilder.build()); + return Optional.of(instructionBuilder.build()); + } +} diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/flow/cases/GoToTableCase.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/flow/cases/GoToTableCase.java new file mode 100644 index 0000000000..c3f66b033a --- /dev/null +++ b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/flow/cases/GoToTableCase.java @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * 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.cases; + +import java.util.Optional; +import javax.annotation.Nonnull; +import org.opendaylight.openflowplugin.api.OFConstants; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.data.ActionConvertorData; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.ConvertorCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.go.to.table._case.GoToTable; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instruction.grouping.instruction.choice.GotoTableCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instruction.grouping.instruction.choice._goto.table._case.GotoTableBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instructions.grouping.Instruction; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instructions.grouping.InstructionBuilder; + +public class GoToTableCase extends ConvertorCase { + public GoToTableCase() { + super(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.GoToTableCase.class, true, OFConstants.OFP_VERSION_1_0, OFConstants.OFP_VERSION_1_3); + } + + @Override + public Optional process(final @Nonnull org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.GoToTableCase source, final ActionConvertorData data) { + GoToTable goToTable = source.getGoToTable(); + GotoTableCaseBuilder gotoTableCaseBuilder = new GotoTableCaseBuilder(); + GotoTableBuilder gotoTableBuilder = new GotoTableBuilder(); + gotoTableBuilder.setTableId(goToTable.getTableId()); + gotoTableCaseBuilder.setGotoTable(gotoTableBuilder.build()); + InstructionBuilder instructionBuilder = new InstructionBuilder(); + instructionBuilder.setInstructionChoice(gotoTableCaseBuilder.build()); + return Optional.of(instructionBuilder.build()); + } +} diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/flow/cases/MeterCase.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/flow/cases/MeterCase.java new file mode 100644 index 0000000000..20913d43bc --- /dev/null +++ b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/flow/cases/MeterCase.java @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * 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.cases; + +import java.util.Optional; +import javax.annotation.Nonnull; +import org.opendaylight.openflowplugin.api.OFConstants; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.data.ActionConvertorData; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.ConvertorCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.meter._case.Meter; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instruction.grouping.instruction.choice.MeterCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instruction.grouping.instruction.choice.meter._case.MeterBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instructions.grouping.Instruction; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instructions.grouping.InstructionBuilder; + +public class MeterCase extends ConvertorCase { + public MeterCase() { + super(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.MeterCase.class, true, OFConstants.OFP_VERSION_1_0, OFConstants.OFP_VERSION_1_3); + } + + @Override + public Optional process(final @Nonnull org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.MeterCase source, final ActionConvertorData data) { + Meter meter = source.getMeter(); + MeterCaseBuilder meterCaseBuilder = new MeterCaseBuilder(); + MeterBuilder meterBuilder = new MeterBuilder(); + Long meterId = meter.getMeterId().getValue(); + meterBuilder.setMeterId(meterId); + meterCaseBuilder.setMeter(meterBuilder.build()); + InstructionBuilder instructionBuilder = new InstructionBuilder(); + instructionBuilder.setInstructionChoice(meterCaseBuilder.build()); + return Optional.of(instructionBuilder.build()); + } +} diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/flow/cases/WriteActionsCase.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/flow/cases/WriteActionsCase.java new file mode 100644 index 0000000000..f3b83bd20f --- /dev/null +++ b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/flow/cases/WriteActionsCase.java @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * 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.cases; + +import java.util.Collections; +import java.util.List; +import java.util.Optional; +import javax.annotation.Nonnull; +import org.opendaylight.openflowplugin.api.OFConstants; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorManager; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.data.ActionConvertorData; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.ConvertorCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.write.actions._case.WriteActions; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.Action; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instruction.grouping.instruction.choice.WriteActionsCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instruction.grouping.instruction.choice.write.actions._case.WriteActionsBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instructions.grouping.Instruction; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instructions.grouping.InstructionBuilder; + +public class WriteActionsCase extends ConvertorCase { + public WriteActionsCase() { + super(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.WriteActionsCase.class, true, OFConstants.OFP_VERSION_1_0, OFConstants.OFP_VERSION_1_3); + } + + @Override + public Optional process(final @Nonnull org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.WriteActionsCase source, final ActionConvertorData data) { + WriteActions writeActions = source.getWriteActions(); + WriteActionsCaseBuilder writeActionsCaseBuilder = new WriteActionsCaseBuilder(); + WriteActionsBuilder writeActionsBuilder = new WriteActionsBuilder(); + + final Optional> actions = ConvertorManager.getInstance().convert( + writeActions.getAction(), data); + + writeActionsBuilder.setAction(actions.orElse(Collections.emptyList())); + writeActionsCaseBuilder.setWriteActions(writeActionsBuilder.build()); + InstructionBuilder instructionBuilder = new InstructionBuilder(); + instructionBuilder.setInstructionChoice(writeActionsCaseBuilder.build()); + return Optional.of(instructionBuilder.build()); + } +} diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/flow/cases/WriteMetadataCase.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/flow/cases/WriteMetadataCase.java new file mode 100644 index 0000000000..87b3afd5bc --- /dev/null +++ b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/flow/cases/WriteMetadataCase.java @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * 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.cases; + +import java.util.Optional; +import javax.annotation.Nonnull; +import org.opendaylight.openflowplugin.api.OFConstants; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.data.ActionConvertorData; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.ConvertorCase; +import org.opendaylight.openflowplugin.openflow.md.util.ByteUtil; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.write.metadata._case.WriteMetadata; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instruction.grouping.instruction.choice.WriteMetadataCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instruction.grouping.instruction.choice.write.metadata._case.WriteMetadataBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instructions.grouping.Instruction; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instructions.grouping.InstructionBuilder; + +public class WriteMetadataCase extends ConvertorCase { + public WriteMetadataCase() { + super(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.WriteMetadataCase.class, true, OFConstants.OFP_VERSION_1_0, OFConstants.OFP_VERSION_1_3); + } + + @Override + public Optional process(final @Nonnull org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.WriteMetadataCase source, final ActionConvertorData data) { + WriteMetadata writeMetadata = source.getWriteMetadata(); + WriteMetadataCaseBuilder writeMetadataCaseBuilder = new WriteMetadataCaseBuilder(); + WriteMetadataBuilder writeMetadataBuilder = new WriteMetadataBuilder(); + writeMetadataBuilder.setMetadata(ByteUtil.convertBigIntegerToNBytes(writeMetadata.getMetadata(), OFConstants.SIZE_OF_LONG_IN_BYTES)); + writeMetadataBuilder.setMetadataMask(ByteUtil.convertBigIntegerToNBytes(writeMetadata.getMetadataMask(), OFConstants.SIZE_OF_LONG_IN_BYTES)); + writeMetadataCaseBuilder.setWriteMetadata(writeMetadataBuilder.build()); + InstructionBuilder instructionBuilder = new InstructionBuilder(); + instructionBuilder.setInstructionChoice(writeMetadataCaseBuilder.build()); + return Optional.of(instructionBuilder.build()); + } +} diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/flowflag/FlowFlagConvertor.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/flow/flowflag/FlowFlagConvertor.java similarity index 93% rename from openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/flowflag/FlowFlagConvertor.java rename to openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/flow/flowflag/FlowFlagConvertor.java index d1011f3042..a22808d049 100644 --- a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/flowflag/FlowFlagConvertor.java +++ b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/flow/flowflag/FlowFlagConvertor.java @@ -1,4 +1,4 @@ -/** +/* * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. * * This program and the accompanying materials are made available under the @@ -6,14 +6,15 @@ * and is available at http://www.eclipse.org/legal/epl-v10.html */ -package org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.flowflag; +package org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.flow.flowflag; import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.Convertor; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowModFlags; /** * converting from MD-SAL match model into appropriate OF-API match model - * @param type of converted match + * + * @param type of converted match */ public interface FlowFlagConvertor extends Convertor { diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/flowflag/FlowFlagReactor.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/flow/flowflag/FlowFlagReactor.java similarity index 92% rename from openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/flowflag/FlowFlagReactor.java rename to openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/flow/flowflag/FlowFlagReactor.java index 05f6a5a064..f4e51a8e9b 100644 --- a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/flowflag/FlowFlagReactor.java +++ b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/flow/flowflag/FlowFlagReactor.java @@ -1,4 +1,4 @@ -/** +/* * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. * * This program and the accompanying materials are made available under the @@ -6,10 +6,9 @@ * and is available at http://www.eclipse.org/legal/epl-v10.html */ -package org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.flowflag; +package org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.flow.flowflag; import java.util.Map; - import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.ConvertReactor; import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.Convertor; import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.InjectionKey; @@ -36,7 +35,7 @@ public class FlowFlagReactor extends ConvertReactor { @Override protected void initMappings(final Map> conversions, - final Map> injections) { + final Map> injections) { FlowFlagReactorMappingFactory.addFlowFlagsConvertors(conversions); FlowFlagReactorMappingFactory.addFlowFlagsIjectors(injections); } diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/flowflag/FlowFlagReactorMappingFactory.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/flow/flowflag/FlowFlagReactorMappingFactory.java similarity index 80% rename from openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/flowflag/FlowFlagReactorMappingFactory.java rename to openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/flow/flowflag/FlowFlagReactorMappingFactory.java index bb5a685b27..fac616de9e 100644 --- a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/flowflag/FlowFlagReactorMappingFactory.java +++ b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/flow/flowflag/FlowFlagReactorMappingFactory.java @@ -1,4 +1,4 @@ -/** +/* * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. * * This program and the accompanying materials are made available under the @@ -6,10 +6,9 @@ * and is available at http://www.eclipse.org/legal/epl-v10.html */ -package org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.flowflag; +package org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.flow.flowflag; import java.util.Map; - import org.opendaylight.openflowplugin.api.OFConstants; import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.Convertor; import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.InjectionKey; @@ -20,6 +19,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731 /** * add prepared convertors and injectors into given mappings + * * @see FlowFlagReactor */ public class FlowFlagReactorMappingFactory { @@ -39,22 +39,22 @@ public class FlowFlagReactorMappingFactory { // OF-1.3|FlowModFlags --> FlowModInputBuilder injectionMapping.put(new InjectionKey(OFConstants.OFP_VERSION_1_3, FlowModInputBuilder.class), new ResultInjector() { - @Override - public void inject(final FlowModFlags value, - final FlowModInputBuilder target) { - target.setFlags(value); - } - }); + @Override + public void inject(final FlowModFlags value, + final FlowModInputBuilder target) { + target.setFlags(value); + } + }); // OF-1.3|FlowModFlagsV10 --> FlowModInputBuilder injectionMapping.put(new InjectionKey(OFConstants.OFP_VERSION_1_0, FlowModInputBuilder.class), new ResultInjector() { - @Override - public void inject(final FlowModFlagsV10 value, - final FlowModInputBuilder target) { - target.setFlagsV10(value); - } - }); + @Override + public void inject(final FlowModFlagsV10 value, + final FlowModInputBuilder target) { + target.setFlagsV10(value); + } + }); } diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/flowflag/FlowFlagsConvertorImpl.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/flow/flowflag/FlowFlagsConvertorImpl.java similarity index 80% rename from openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/flowflag/FlowFlagsConvertorImpl.java rename to openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/flow/flowflag/FlowFlagsConvertorImpl.java index 2dfb2acf85..3604727c52 100644 --- a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/flowflag/FlowFlagsConvertorImpl.java +++ b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/flow/flowflag/FlowFlagsConvertorImpl.java @@ -1,4 +1,4 @@ -/** +/* * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. * * This program and the accompanying materials are made available under the @@ -6,34 +6,34 @@ * and is available at http://www.eclipse.org/legal/epl-v10.html */ -package org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.flowflag; +package org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.flow.flowflag; -import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.FlowConvertor; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.flow.FlowConvertor; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.FlowModFlags; /** - * + * */ public class FlowFlagsConvertorImpl implements FlowFlagConvertor { @Override public FlowModFlags convert( org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowModFlags source) { - - FlowModFlags ofFlowModFlags = null; + + FlowModFlags ofFlowModFlags; if (source != null) { ofFlowModFlags = new FlowModFlags( source.isCHECKOVERLAP(), source.isNOBYTCOUNTS(), source.isNOPKTCOUNTS(), source.isRESETCOUNTS(), source.isSENDFLOWREM()); } else { ofFlowModFlags = new FlowModFlags( - FlowConvertor.DEFAULT_OFPFF_CHECK_OVERLAP, - FlowConvertor.DEFAULT_OFPFF_NO_BYT_COUNTS, + FlowConvertor.DEFAULT_OFPFF_CHECK_OVERLAP, + FlowConvertor.DEFAULT_OFPFF_NO_BYT_COUNTS, FlowConvertor.DEFAULT_OFPFF_NO_PKT_COUNTS, - FlowConvertor.DEFAULT_OFPFF_RESET_COUNTS, + FlowConvertor.DEFAULT_OFPFF_RESET_COUNTS, FlowConvertor.DEFAULT_OFPFF_FLOW_REM); } - + return ofFlowModFlags; } } diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/flowflag/FlowFlagsConvertorV10Impl.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/flow/flowflag/FlowFlagsConvertorV10Impl.java similarity index 75% rename from openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/flowflag/FlowFlagsConvertorV10Impl.java rename to openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/flow/flowflag/FlowFlagsConvertorV10Impl.java index ee5dac9b1d..f37f03760c 100644 --- a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/flowflag/FlowFlagsConvertorV10Impl.java +++ b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/flow/flowflag/FlowFlagsConvertorV10Impl.java @@ -1,4 +1,4 @@ -/** +/* * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. * * This program and the accompanying materials are made available under the @@ -6,31 +6,32 @@ * and is available at http://www.eclipse.org/legal/epl-v10.html */ -package org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.flowflag; +package org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.flow.flowflag; -import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.FlowConvertor; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.flow.FlowConvertor; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowModFlags; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.FlowModFlagsV10; /** - * + * */ public class FlowFlagsConvertorV10Impl implements FlowFlagConvertor { @Override public FlowModFlagsV10 convert( - org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowModFlags source) { - - FlowModFlagsV10 ofFlowModFlags = null; + FlowModFlags source) { + + FlowModFlagsV10 ofFlowModFlags; if (source != null) { ofFlowModFlags = new FlowModFlagsV10( source.isCHECKOVERLAP(), FlowConvertor.DEFAULT_OFPFF_EMERGENCY, source.isSENDFLOWREM()); } else { ofFlowModFlags = new FlowModFlagsV10( - FlowConvertor.DEFAULT_OFPFF_CHECK_OVERLAP, - FlowConvertor.DEFAULT_OFPFF_EMERGENCY, + FlowConvertor.DEFAULT_OFPFF_CHECK_OVERLAP, + FlowConvertor.DEFAULT_OFPFF_EMERGENCY, FlowConvertor.DEFAULT_OFPFF_FLOW_REM); } - + return ofFlowModFlags; } } diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/match/MatchReactorMappingFactory.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/match/MatchReactorMappingFactory.java index 1226fdf569..6dfeeb3b5f 100644 --- a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/match/MatchReactorMappingFactory.java +++ b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/match/MatchReactorMappingFactory.java @@ -11,10 +11,10 @@ package org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.match; import java.util.List; import java.util.Map; import org.opendaylight.openflowplugin.api.OFConstants; -import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.FlowConvertor; import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.Convertor; import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.InjectionKey; import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.ResultInjector; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.flow.FlowConvertor; import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.Match; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.set.field._case.SetFieldActionBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntry; diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/translator/MultipartReplyTranslator.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/translator/MultipartReplyTranslator.java index 94295ca69c..4872f58a8c 100644 --- a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/translator/MultipartReplyTranslator.java +++ b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/translator/MultipartReplyTranslator.java @@ -19,13 +19,14 @@ import org.opendaylight.openflowplugin.api.openflow.md.core.SwitchConnectionDist import org.opendaylight.openflowplugin.api.openflow.md.core.session.SessionContext; import org.opendaylight.openflowplugin.api.openflow.md.util.OpenflowVersion; import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorManager; -import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.FlowStatsResponseConvertor; 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.openflowplugin.openflow.md.util.InventoryDataServiceUtil; 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.AggregateFlowStatisticsUpdateBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.FlowsStatisticsUpdateBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.flow.and.statistics.map.list.FlowAndStatisticsMapList; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.FlowTableStatisticsUpdateBuilder; 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; @@ -113,8 +114,6 @@ public class MultipartReplyTranslator implements IMDMessageTranslator translate(final SwitchConnectionDistinguisher cookie, final SessionContext sc, final OfHeader msg) { @@ -135,8 +134,12 @@ public class MultipartReplyTranslator implements IMDMessageTranslator> flowAndStatisticsMapLists = ConvertorManager.getInstance().convert(replyBody.getFlowStats(), data); + message.setFlowAndStatisticsMapList(flowAndStatisticsMapLists.orElse(Collections.emptyList())); logger.debug("Converted flow statistics : {}",message.build().toString()); listDataObject.add(message.build()); return listDataObject; diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/util/FlowCreatorUtil.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/util/FlowCreatorUtil.java index d4d3bc9e39..639bf1e4f0 100644 --- a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/util/FlowCreatorUtil.java +++ b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/util/FlowCreatorUtil.java @@ -11,9 +11,9 @@ package org.opendaylight.openflowplugin.openflow.md.util; import java.math.BigInteger; import java.util.Objects; import org.opendaylight.openflowplugin.api.OFConstants; -import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.FlowConvertor; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.flow.FlowConvertor; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.flow.update.OriginalFlow; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.flow.update.UpdatedFlow; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowCookie; diff --git a/openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/FlowConverterTest.java b/openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/FlowConverterTest.java deleted file mode 100644 index b45e3e5dab..0000000000 --- a/openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/FlowConverterTest.java +++ /dev/null @@ -1,231 +0,0 @@ -/** - * Copyright (c) 2014 Ericsson India Global Services Pvt Ltd. and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * 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; - -import java.math.BigInteger; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; -import org.junit.Assert; -import org.junit.Test; -import org.opendaylight.openflowplugin.api.OFConstants; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Uri; -import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetVlanIdActionCaseBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.vlan.id.action._case.SetVlanIdActionBuilder; -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.flow.service.rev130819.AddFlowInput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.FlowTableRef; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.Flow; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowCookie; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowModFlags; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowRef; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Instructions; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.InstructionsBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Match; -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.InstructionBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRef; -import org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.EtherType; -import org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanId; -import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ethernet.match.fields.EthernetTypeBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.EthernetMatch; -import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.EthernetMatchBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowModInputBuilder; -import org.opendaylight.yangtools.yang.binding.Augmentation; -import org.opendaylight.yangtools.yang.binding.DataContainer; - -/** - * test for {@link org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.FlowConvertor} - */ -public class FlowConverterTest { - - - @Test - public void testCloneAndAugmentFlowWithSetVlanId() { - MockFlow mockFlow = new MockFlow(); - Action action1 = createAction( - new SetVlanIdActionCaseBuilder().setSetVlanIdAction( - new SetVlanIdActionBuilder().setVlanId(new VlanId(10)).build()) - .build(), - 0); - - mockFlow.setMatch(new MatchBuilder().setEthernetMatch(createEthernetMatch()).build()); - mockFlow.setInstructions(toApplyInstruction(Collections.singletonList(action1))); - - List flowModInputBuilders = - FlowConvertor.toFlowModInputs(mockFlow, OFConstants.OFP_VERSION_1_3, BigInteger.ONE); - Assert.assertEquals(2, flowModInputBuilders.size()); - - } - - private static Action createAction(final org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action actionCase, - final int order) { - Action action = new ActionBuilder().setOrder(order).setAction(actionCase).build(); - return action; - } - - private static EthernetMatch createEthernetMatch() { - EthernetMatchBuilder ethernetMatchBuilder = new EthernetMatchBuilder(); - ethernetMatchBuilder.setEthernetType(new EthernetTypeBuilder().setType(new EtherType(33024L)).build()); - return ethernetMatchBuilder.build(); - } - - private static Instructions toApplyInstruction( - final List actions) { - return new InstructionsBuilder() - .setInstruction( - Collections.singletonList( - new InstructionBuilder() - .setOrder(0) - .setInstruction( - new ApplyActionsCaseBuilder() - .setApplyActions((new ApplyActionsBuilder()).setAction(actions).build()) - .build() - ).build()) - ).build(); - } - - private static Flow createFlowWithActions(final Action...actions) { - MockFlow mockFlow = new MockFlow(); - mockFlow.setInstructions(toApplyInstruction(Arrays.asList(actions))); - return mockFlow; - } - - private static class MockFlow implements AddFlowInput { - private Instructions instructions; - private Match match; - - public void setInstructions(final Instructions instructions) { - this.instructions = instructions; - } - - public void setMatch(final Match match) { - this.match = match; - } - - - @Override - public FlowRef getFlowRef() { - return null; - } - - @Override - public > E getAugmentation(final Class augmentationType) { - return null; - } - - @Override - public FlowTableRef getFlowTable() { - return null; - } - - @Override - public Match getMatch() { - return match; - } - - @Override - public Instructions getInstructions() { - return instructions; - } - - @Override - public String getContainerName() { - return null; - } - - @Override - public FlowCookie getCookieMask() { - return null; - } - - @Override - public Long getBufferId() { - return null; - } - - @Override - public BigInteger getOutPort() { - return null; - } - - @Override - public Long getOutGroup() { - return null; - } - - @Override - public FlowModFlags getFlags() { - return null; - } - - @Override - public String getFlowName() { - return null; - } - - @Override - public Boolean isInstallHw() { - return null; - } - - @Override - public Boolean isBarrier() { - return null; - } - - @Override - public Boolean isStrict() { - return null; - } - - @Override - public Integer getPriority() { - return null; - } - - @Override - public Integer getIdleTimeout() { - return null; - } - - @Override - public Integer getHardTimeout() { - return null; - } - - @Override - public FlowCookie getCookie() { - return null; - } - - @Override - public Short getTableId() { - return null; - } - - @Override - public NodeRef getNode() { - return null; - } - - @Override - public Uri getTransactionUri() { - return null; - } - - @Override - public Class getImplementedInterface() { - return null; - } - } - -} diff --git a/openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/ActionConvertorV10Test.java b/openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/ActionConvertorV10Test.java index 6ebb124839..2a84783aa4 100644 --- a/openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/ActionConvertorV10Test.java +++ b/openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/ActionConvertorV10Test.java @@ -20,6 +20,7 @@ import org.opendaylight.openflowplugin.extension.api.path.ActionPath; import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorManager; import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.data.ActionConvertorData; import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.data.ActionResponseConvertorData; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.flow.FlowConvertorUtil; import org.opendaylight.openflowplugin.openflow.md.util.OpenflowPortsUtil; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpVersion; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix; @@ -202,9 +203,7 @@ public class ActionConvertorV10Test { ActionConvertorData data = new ActionConvertorData(OFConstants.OFP_VERSION_1_0); data.setDatapathId(new BigInteger("42")); - if (flow.getMatch() != null && flow.getMatch().getIpMatch() != null) { - data.setIpProtocol(flow.getMatch().getIpMatch().getIpProtocol()); - } + data.setIpProtocol(FlowConvertorUtil.getIpProtocolFromFlow(flow)); Optional> actionsOptional = ConvertorManager.getInstance().convert(salActions, data); diff --git a/openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/ActionConvertorV13Test.java b/openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/ActionConvertorV13Test.java index 503881d23c..a26e3bc684 100644 --- a/openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/ActionConvertorV13Test.java +++ b/openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/ActionConvertorV13Test.java @@ -20,6 +20,7 @@ import org.opendaylight.openflowplugin.extension.api.path.ActionPath; import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorManager; import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.data.ActionConvertorData; import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.data.ActionResponseConvertorData; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.flow.FlowConvertorUtil; import org.opendaylight.openflowplugin.openflow.md.util.OpenflowPortsUtil; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Prefix; @@ -499,10 +500,7 @@ public class ActionConvertorV13Test { ActionConvertorData data = new ActionConvertorData(OFConstants.OFP_VERSION_1_3); data.setDatapathId(new BigInteger("42")); - - if (flow.getMatch() != null && flow.getMatch().getIpMatch() != null) { - data.setIpProtocol(flow.getMatch().getIpMatch().getIpProtocol()); - } + data.setIpProtocol(FlowConvertorUtil.getIpProtocolFromFlow(flow)); Optional> actionsOptional = ConvertorManager.getInstance().convert(salActions, data); List actions = actionsOptional.orElse(Collections.emptyList()); diff --git a/openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/FlowConvertorTest.java b/openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/flow/FlowConvertorTest.java similarity index 60% rename from openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/FlowConvertorTest.java rename to openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/flow/FlowConvertorTest.java index 210f9f255c..e51a13ca9b 100644 --- a/openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/FlowConvertorTest.java +++ b/openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/flow/FlowConvertorTest.java @@ -6,24 +6,37 @@ * and is available at http://www.eclipse.org/legal/epl-v10.html */ -package org.opendaylight.openflowplugin.openflow.md.core.sal.convertor; +package org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.flow; import java.math.BigInteger; import java.util.ArrayList; +import java.util.Collections; import java.util.List; +import java.util.Optional; import org.junit.Assert; import org.junit.Test; -import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants; +import org.opendaylight.openflowplugin.api.OFConstants; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorManager; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.data.VersionDatapathIdConvertorData; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Uri; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetVlanIdActionCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.vlan.id.action._case.SetVlanIdActionBuilder; 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.flow.service.rev130819.AddFlowInput; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowInputBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.FlowTableRef; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.RemoveFlowInput; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.RemoveFlowInputBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.flow.update.UpdatedFlow; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.flow.update.UpdatedFlowBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.Flow; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowCookie; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowRef; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Instructions; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.InstructionsBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Match; +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.ClearActionsCaseBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.GoToTableCaseBuilder; @@ -38,7 +51,13 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instru import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.write.metadata._case.WriteMetadataBuilder; 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.inventory.rev130819.NodeRef; +import org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.EtherType; +import org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanId; import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.MeterId; +import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ethernet.match.fields.EthernetTypeBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.EthernetMatch; +import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.EthernetMatchBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instruction.grouping.instruction.choice.ApplyActionsCase; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instruction.grouping.instruction.choice.GotoTableCase; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instruction.grouping.instruction.choice.MeterCase; @@ -47,6 +66,8 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.FlowModCommand; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.FlowModFlags; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowModInputBuilder; +import org.opendaylight.yangtools.yang.binding.Augmentation; +import org.opendaylight.yangtools.yang.binding.DataContainer; /** * @author michal.polkorab @@ -55,7 +76,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731 public class FlowConvertorTest { /** - * Tests {@link FlowConvertor#toFlowModInputs(Flow, short, BigInteger)} + * Tests {@link org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.flow.FlowConvertor#convert(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.Flow, org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.data.VersionDatapathIdConvertorData)} } */ @Test public void test() { @@ -75,8 +96,10 @@ public class FlowConvertorTest { flowBuilder.setMatch(null); RemoveFlowInput flow = flowBuilder.build(); - List flowMod = FlowConvertor - .toFlowModInputs(flow, EncodeConstants.OF13_VERSION_ID, new BigInteger("42")); + VersionDatapathIdConvertorData data = new VersionDatapathIdConvertorData(OFConstants.OFP_VERSION_1_3); + data.setDatapathId(new BigInteger("42")); + + List flowMod = convert(flow, data); Assert.assertEquals("Wrong version", 4, flowMod.get(0).getVersion().intValue()); Assert.assertEquals("Wrong cookie", 4, flowMod.get(0).getCookie().intValue()); @@ -96,7 +119,7 @@ public class FlowConvertorTest { } /** - * Tests {@link FlowConvertor#toFlowModInputs(Flow, short, BigInteger)} + * Tests {@link org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.flow.FlowConvertor#convert(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.Flow, org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.data.VersionDatapathIdConvertorData)} } */ @Test public void testOnlyModifyStrictCommand() { @@ -104,15 +127,17 @@ public class FlowConvertorTest { flowBuilder.setStrict(true); UpdatedFlow flow = flowBuilder.build(); - List flowMod = FlowConvertor - .toFlowModInputs(flow, EncodeConstants.OF10_VERSION_ID, new BigInteger("42")); + VersionDatapathIdConvertorData data = new VersionDatapathIdConvertorData(OFConstants.OFP_VERSION_1_0); + data.setDatapathId(new BigInteger("42")); + + List flowMod = convert(flow, data); Assert.assertEquals("Wrong version", 1, flowMod.get(0).getVersion().intValue()); Assert.assertEquals("Wrong command", FlowModCommand.OFPFCADD, flowMod.get(0).getCommand()); } /** - * Tests {@link FlowConvertor#toFlowModInputs(Flow, short, BigInteger)} + * Tests {@link org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.flow.FlowConvertor#convert(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.Flow, org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.data.VersionDatapathIdConvertorData)} } */ @Test public void testInstructionsTranslation() { @@ -175,8 +200,9 @@ public class FlowConvertorTest { flowBuilder.setInstructions(instructionsBuilder.build()); AddFlowInput flow = flowBuilder.build(); - List flowMod = FlowConvertor - .toFlowModInputs(flow, EncodeConstants.OF10_VERSION_ID, new BigInteger("42")); + VersionDatapathIdConvertorData data = new VersionDatapathIdConvertorData(OFConstants.OFP_VERSION_1_0); + data.setDatapathId(new BigInteger("42")); + List flowMod = convert(flow, data); Assert.assertEquals("Wrong version", 1, flowMod.get(0).getVersion().intValue()); Assert.assertEquals("Wrong command", FlowModCommand.OFPFCADD, flowMod.get(0).getCommand()); @@ -215,4 +241,187 @@ public class FlowConvertorTest { MeterCase meterCase = (MeterCase) instruction.getInstructionChoice(); Assert.assertEquals("Wrong meter id", 5, meterCase.getMeter().getMeterId().intValue()); } + + @Test + public void testCloneAndAugmentFlowWithSetVlanId() { + MockFlow mockFlow = new MockFlow(); + Action action1 = createAction( + new SetVlanIdActionCaseBuilder().setSetVlanIdAction( + new SetVlanIdActionBuilder().setVlanId(new VlanId(10)).build()) + .build(), + 0); + + mockFlow.setMatch(new MatchBuilder().setEthernetMatch(createEthernetMatch()).build()); + mockFlow.setInstructions(toApplyInstruction(Collections.singletonList(action1))); + + VersionDatapathIdConvertorData data = new VersionDatapathIdConvertorData(OFConstants.OFP_VERSION_1_3); + data.setDatapathId(BigInteger.ONE); + + List flowModInputBuilders = convert(mockFlow, data); + + Assert.assertEquals(2, flowModInputBuilders.size()); + + } + + private List convert(Flow flow, VersionDatapathIdConvertorData data) { + Optional> flowModOptional = ConvertorManager.getInstance().convert(flow, data); + Assert.assertTrue("Flow convertor not found", flowModOptional.isPresent()); + return flowModOptional.get(); + } + + private static Action createAction(final org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action actionCase, + final int order) { + Action action = new ActionBuilder().setOrder(order).setAction(actionCase).build(); + return action; + } + + private static EthernetMatch createEthernetMatch() { + EthernetMatchBuilder ethernetMatchBuilder = new EthernetMatchBuilder(); + ethernetMatchBuilder.setEthernetType(new EthernetTypeBuilder().setType(new EtherType(33024L)).build()); + return ethernetMatchBuilder.build(); + } + + private static Instructions toApplyInstruction( + final List actions) { + return new InstructionsBuilder() + .setInstruction( + Collections.singletonList( + new InstructionBuilder() + .setOrder(0) + .setInstruction( + new ApplyActionsCaseBuilder() + .setApplyActions((new ApplyActionsBuilder()).setAction(actions).build()) + .build() + ).build()) + ).build(); + } + + private static class MockFlow implements AddFlowInput { + private Instructions instructions; + private Match match; + + public void setInstructions(final Instructions instructions) { + this.instructions = instructions; + } + + public void setMatch(final Match match) { + this.match = match; + } + + + @Override + public FlowRef getFlowRef() { + return null; + } + + @Override + public > E getAugmentation(final Class augmentationType) { + return null; + } + + @Override + public FlowTableRef getFlowTable() { + return null; + } + + @Override + public Match getMatch() { + return match; + } + + @Override + public Instructions getInstructions() { + return instructions; + } + + @Override + public String getContainerName() { + return null; + } + + @Override + public FlowCookie getCookieMask() { + return null; + } + + @Override + public Long getBufferId() { + return null; + } + + @Override + public BigInteger getOutPort() { + return null; + } + + @Override + public Long getOutGroup() { + return null; + } + + @Override + public org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowModFlags getFlags() { + return null; + } + + @Override + public String getFlowName() { + return null; + } + + @Override + public Boolean isInstallHw() { + return null; + } + + @Override + public Boolean isBarrier() { + return null; + } + + @Override + public Boolean isStrict() { + return null; + } + + @Override + public Integer getPriority() { + return null; + } + + @Override + public Integer getIdleTimeout() { + return null; + } + + @Override + public Integer getHardTimeout() { + return null; + } + + @Override + public FlowCookie getCookie() { + return null; + } + + @Override + public Short getTableId() { + return null; + } + + @Override + public NodeRef getNode() { + return null; + } + + @Override + public Uri getTransactionUri() { + return null; + } + + @Override + public Class getImplementedInterface() { + return null; + } + } } \ No newline at end of file diff --git a/openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/OFToMDSalFlowConvertorTest.java b/openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/flow/FlowStatsResponseConvertorTest.java similarity index 82% rename from openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/OFToMDSalFlowConvertorTest.java rename to openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/flow/FlowStatsResponseConvertorTest.java index d4c49a9262..1081f6df13 100644 --- a/openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/OFToMDSalFlowConvertorTest.java +++ b/openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/flow/FlowStatsResponseConvertorTest.java @@ -6,17 +6,20 @@ * and is available at http://www.eclipse.org/legal/epl-v10.html */ -package org.opendaylight.openflowplugin.openflow.md.core.sal.convertor; +package org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.flow; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; import java.math.BigInteger; import java.util.ArrayList; import java.util.List; - +import java.util.Optional; import org.junit.Test; -import org.opendaylight.openflowplugin.api.openflow.md.util.OpenflowVersion; +import org.opendaylight.openflowplugin.api.OFConstants; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorManager; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.data.VersionConvertorData; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Instructions; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.Action; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.ActionBuilder; @@ -38,12 +41,12 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev13 /** * Created by Martin Bobak mbobak@cisco.com on 9/18/14. */ -public class OFToMDSalFlowConvertorTest { +public class FlowStatsResponseConvertorTest { private static final int PRESET_COUNT = 7; /** - * Test method for {@link OFToMDSalFlowConvertor#wrapOF10ActionsToInstruction(java.util.List, org.opendaylight.openflowplugin.api.openflow.md.util.OpenflowVersion)} + * Test method for {@link FlowStatsResponseConvertor#wrapOF10ActionsToInstruction(java.util.List, short)} } */ @Test public void testWrapOF10ActionsToInstruction() { @@ -52,12 +55,12 @@ public class OFToMDSalFlowConvertorTest { for (int j = 0; j < PRESET_COUNT; j++) { actions.add(actionBuilder.build()); } - Instructions instructions = OFToMDSalFlowConvertor.wrapOF10ActionsToInstruction(actions, OpenflowVersion.OF13); + Instructions instructions = FlowStatsResponseConvertor.wrapOF10ActionsToInstruction(actions, OFConstants.OFP_VERSION_1_3); assertNotNull(instructions); } /** - * Test method for {@link OFToMDSalFlowConvertor#toSALInstruction(java.util.List, org.opendaylight.openflowplugin.api.openflow.md.util.OpenflowVersion)} + * Test method for {@link FlowInstructionResponseConvertor#convert(java.util.List, org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.data.VersionConvertorData)} } */ @Test public void testToSALInstruction() { @@ -77,7 +80,10 @@ public class OFToMDSalFlowConvertorTest { instructionsList.add(instructionBuilder.build()); } - Instructions instructions = OFToMDSalFlowConvertor.toSALInstruction(instructionsList, OpenflowVersion.OF13); + Instructions instructions; + VersionConvertorData data = new VersionConvertorData(OFConstants.OFP_VERSION_1_3); + + instructions = convert(instructionsList, data); assertNotNull(instructions); assertEquals(PRESET_COUNT, instructions.getInstruction().size()); @@ -91,7 +97,7 @@ public class OFToMDSalFlowConvertorTest { instructionsList.add(instructionBuilder.build()); } - instructions = OFToMDSalFlowConvertor.toSALInstruction(instructionsList, OpenflowVersion.OF13); + instructions = convert(instructionsList, data); assertNotNull(instructions); assertEquals(PRESET_COUNT, instructions.getInstruction().size()); @@ -99,13 +105,13 @@ public class OFToMDSalFlowConvertorTest { for (int i = 0; i < PRESET_COUNT; i++) { MeterCaseBuilder meterCaseBuilder = new MeterCaseBuilder(); MeterBuilder meterBuilder = new MeterBuilder(); - meterBuilder.setMeterId(Long.valueOf(i)); + meterBuilder.setMeterId((long) i); meterCaseBuilder.setMeter(meterBuilder.build()); instructionBuilder.setInstructionChoice(meterCaseBuilder.build()); instructionsList.add(instructionBuilder.build()); } - instructions = OFToMDSalFlowConvertor.toSALInstruction(instructionsList, OpenflowVersion.OF13); + instructions = convert(instructionsList, data); assertNotNull(instructions); assertEquals(PRESET_COUNT, instructions.getInstruction().size()); @@ -125,7 +131,7 @@ public class OFToMDSalFlowConvertorTest { instructionsList.add(instructionBuilder.build()); } - instructions = OFToMDSalFlowConvertor.toSALInstruction(instructionsList, OpenflowVersion.OF13); + instructions = convert(instructionsList, data); assertNotNull(instructions); assertEquals(PRESET_COUNT, instructions.getInstruction().size()); @@ -136,7 +142,7 @@ public class OFToMDSalFlowConvertorTest { instructionsList.add(instructionBuilder.build()); } - instructions = OFToMDSalFlowConvertor.toSALInstruction(instructionsList, OpenflowVersion.OF13); + instructions = convert(instructionsList, data); assertNotNull(instructions); int instructionSize = instructions.getInstruction().size(); assertEquals(PRESET_COUNT, instructionSize); @@ -153,11 +159,17 @@ public class OFToMDSalFlowConvertorTest { instructionsList.add(instructionBuilder.build()); } - instructions = OFToMDSalFlowConvertor.toSALInstruction(instructionsList, OpenflowVersion.OF13); + instructions = convert(instructionsList, data); assertNotNull(instructions); assertEquals(PRESET_COUNT, instructions.getInstruction().size()); } + private Instructions convert(List instructionsList, VersionConvertorData data) { + Optional instructionsOptional = ConvertorManager.getInstance().convert(instructionsList, data); + assertTrue("Flow instruction response convertor not found", instructionsOptional.isPresent()); + return instructionsOptional.get(); + } + private static final class MockActionBase extends ActionBase { // for testing purposes } diff --git a/openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/flowflag/FlowFlagReactorTest.java b/openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/flow/flowflag/FlowFlagReactorTest.java similarity index 98% rename from openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/flowflag/FlowFlagReactorTest.java rename to openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/flow/flowflag/FlowFlagReactorTest.java index ac54c827bb..fe3f5d7ea5 100644 --- a/openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/flowflag/FlowFlagReactorTest.java +++ b/openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/flow/flowflag/FlowFlagReactorTest.java @@ -5,7 +5,7 @@ * 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.flowflag; +package org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.flow.flowflag; import org.junit.Assert; import org.junit.Before; -- 2.36.6