- 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 <tomas.slusny@pantheon.sk>
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;
}
List<FlowModInputBuilder> toFlowModInputs(final Flow input) {
- return FlowConvertor.toFlowModInputs(input, getVersion(), getDatapathId());
+ final VersionDatapathIdConvertorData data = new VersionDatapathIdConvertorData(getVersion());
+ data.setDatapathId(getDatapathId());
+
+ final Optional<List<FlowModInputBuilder>> flowModInputBuilders = ConvertorManager.getInstance().convert(input, data);
+ return flowModInputBuilders.orElse(Collections.emptyList());
}
ListenableFuture<RpcResult<O>> processFlowModInputBuilders(final List<FlowModInputBuilder> ofFlowModInputs) {
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;
protected static final Logger logger = LoggerFactory
.getLogger(SinglePurposeMultipartReplyTranslator.class);
- private static FlowStatsResponseConvertor flowStatsConvertor = new FlowStatsResponseConvertor();
-
public List<DataObject> translate(final BigInteger datapathId, final short version, final OfHeader msg) {
List<DataObject> listDataObject = new ArrayList<>();
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);
private static void translateFlow(final List<DataObject> 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;
}
message.setTransactionId(generateTransactionId(mpReply.getXid()));
MultipartReplyFlowCase caseBody = (MultipartReplyFlowCase) mpReply.getMultipartReplyBody();
MultipartReplyFlow replyBody = caseBody.getMultipartReplyFlow();
- message.setFlowAndStatisticsMapList(flowStatsConvertor.toSALFlowStatsList(replyBody.getFlowStats(), datapathId, ofVersion));
+ final Optional<List<FlowAndStatisticsMapList>> flowAndStatisticsMapLists =
+ ConvertorManager.getInstance().convert(replyBody.getFlowStats(), versionDatapathIdConvertorData);
+
+ message.setFlowAndStatisticsMapList(flowAndStatisticsMapLists.orElse(Collections.emptyList()));
listDataObject.add(message.build());
}
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;
* 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
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<FlowAndStatisticsMapList> statsList = new ArrayList<>();
notification.setId(deviceInfo.getNodeId());
MultipartReplyFlowCase caseBody = (MultipartReplyFlowCase) mpRawReply.getMultipartReplyBody();
MultipartReplyFlow replyBody = caseBody.getMultipartReplyFlow();
- List<FlowAndStatisticsMapList> outStatsItem = flowStatsConvertor.toSALFlowStatsList(
- replyBody.getFlowStats(),
- deviceInfo.getDatapathId(),
- ofVersion);
- statsList.addAll(outStatsItem);
+ final Optional<List<FlowAndStatisticsMapList>> outStatsItem =
+ ConvertorManager.getInstance().convert(replyBody.getFlowStats(), data);
+
+
+ if (outStatsItem.isPresent()) {
+ statsList.addAll(outStatsItem.get());
+ }
}
return notification.build();
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;
* The Flow direct statistics service.
*/
public class FlowDirectStatisticsService extends AbstractDirectStatisticsService<GetFlowStatisticsInput, GetFlowStatisticsOutput> {
- private final FlowStatsResponseConvertor flowStatsConvertor = new FlowStatsResponseConvertor();
-
/**
* Instantiates a new Flow direct statistics service.
*
@Override
protected GetFlowStatisticsOutput buildReply(List<MultipartReply> input, boolean success) {
final List<FlowAndStatisticsMapList> 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<FlowAndStatisticsMapList> 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<List<FlowAndStatisticsMapList>> 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());
+ }
}
}
}
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;
@Override
public ListenableFuture<RpcResult<UpdateFlowOutput>> call() {
ListenableFuture<RpcResult<UpdateFlowOutput>> result = SettableFuture.create();
+ final VersionDatapathIdConvertorData data = new VersionDatapathIdConvertorData(getVersion());
+ data.setDatapathId(getSession().getFeatures().getDatapathId());
// Convert the AddFlowInput to FlowModInput
- List<FlowModInputBuilder> 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<List<FlowModInputBuilder>> ofFlowModInputs =
+ ConvertorManager.getInstance().convert(getInput(), data);
+
+ final List<FlowModInputBuilder> 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(),
Short version = getVersion();
List<FlowModInputBuilder> allFlowMods = new ArrayList<>();
- List<FlowModInputBuilder> ofFlowModInputs;
+ java.util.Optional<List<FlowModInputBuilder>> 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<FlowModInputBuilder> ofFlowRemoveInput = FlowConvertor.toFlowModInputs(removeflow.build(),
- version, getSession().getFeatures().getDatapathId());
- // remove flow should be the first
- allFlowMods.addAll(ofFlowRemoveInput);
+ java.util.Optional<List<FlowModInputBuilder>> 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
}
- 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());
@Override
public ListenableFuture<RpcResult<UpdateFlowOutput>> call() {
ListenableFuture<RpcResult<UpdateFlowOutput>> result = SettableFuture.create();
+ final VersionDatapathIdConvertorData data = new VersionDatapathIdConvertorData(getVersion());
+ data.setDatapathId(getSession().getFeatures().getDatapathId());
// Convert the AddFlowInput to FlowModInput
- List<FlowModInputBuilder> ofFlowModInputs = FlowConvertor.toFlowModInputs(getInput(),
- getVersion(), getSession().getFeatures().getDatapathId());
+ final java.util.Optional<List<FlowModInputBuilder>> 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,
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;
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
+++ /dev/null
-/*
- * 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<FlowAndStatisticsMapList> toSALFlowStatsList(List<FlowStats> allFlowStats, BigInteger datapathid, OpenflowVersion ofVersion){
-
- List<FlowAndStatisticsMapList> convertedSALFlowStats = new ArrayList<FlowAndStatisticsMapList>();
-
- 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> 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<MatchBuilder> matchBuilderOptional = ConvertorManager.getInstance().convert(flowStats.getMatch(), data);
-
- if (matchBuilderOptional.isPresent()) {
- MatchBuilder matchBuilder = matchBuilderOptional.get();
-
- AugmentTuple<Match> 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();
- }
-}
-/**
+/*
* Copyright (c) 2013, 2015 Ericsson. and others. All rights reserved.
*
* This program and the accompanying materials are made available under the
* 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;
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;
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:
+ * <pre>
+ * {@code
+ * VersionDatapathIdConvertorData data = new VersionDatapathIdConvertorData(version);
+ * data.setDatapathId(datapathId);
+ * Optional<List<FlowModInputBuilder>> ofFlow = ConvertorManager.getInstance().convert(salFlow, data);
+ * }
+ * </pre>
*/
-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<Flow, List<FlowModInputBuilder>, VersionDatapathIdConvertorData> {
/**
* Default idle timeout
*/
* 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
*/
/**
* default match entries - empty
*/
- public static final List<MatchEntry> DEFAULT_MATCH_ENTRIES = new ArrayList<MatchEntry>();
- private static final Integer PUSH_VLAN = 0x8100;
-
- private static final Ordering<org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.Instruction> INSTRUCTION_ORDERING =
- Ordering.from(OrderComparator.<org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.Instruction>build());
+ public static final List<MatchEntry> 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<org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.Instruction> INSTRUCTION_ORDERING = Ordering.from(OrderComparator.build());
private static final VlanMatch VLAN_MATCH_FALSE;
private static final VlanMatch VLAN_MATCH_TRUE;
+ private static final ConvertorProcessor<org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.Instruction, Instruction, ActionConvertorData> PROCESSOR = new ConvertorProcessor<org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.Instruction, Instruction, ActionConvertorData>()
+ .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);
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<FlowModInputBuilder> 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();
flowMod.setInstruction(toInstructions(flow, version, datapathid));
flowMod.setAction(getActions(version, datapathid, flow));
}
+
flowMod.setVersion(version);
return flowMod;
}
}
- private static List<Instruction> toInstructions(
- Flow flow,
- short version, BigInteger datapathid) {
- List<Instruction> instructionsList = new ArrayList<>();
+ private static List<Instruction> toInstructions(Flow flow, short version, BigInteger datapathid) {
+ final List<Instruction> 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<Instruction> 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<List<Action>> 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<List<Action>> 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<Action> 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<org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.Instruction> sortedInstructions =
INSTRUCTION_ORDERING.sortedCopy(instructions.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();
+
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<List<Action>> result = ConvertorManager.getInstance().convert(applyActions.getAction(), data);
+ data.setIpProtocol(FlowConvertorUtil.getIpProtocolFromFlow(flow));
+ Optional<List<Action>> result = ConvertorManager.getInstance().convert(applyActions.getAction(), data);
return result.orElse(Collections.emptyList());
}
}
+
return null;
}
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()) {
private static Optional<? extends Flow> injectMatchToFlow(Flow sourceFlow, Match match) {
if (sourceFlow instanceof AddFlowInput) {
- return Optional.<AddFlowInput>of(new AddFlowInputBuilder(sourceFlow).setMatch(match).build());
+ return Optional.of(new AddFlowInputBuilder(sourceFlow).setMatch(match).build());
} else if (sourceFlow instanceof RemoveFlowInput) {
- return Optional.<RemoveFlowInput>of(new RemoveFlowInputBuilder(sourceFlow).setMatch(match).build());
+ return Optional.of(new RemoveFlowInputBuilder(sourceFlow).setMatch(match).build());
} else if (sourceFlow instanceof UpdatedFlow) {
- return Optional.<UpdatedFlow>of(new UpdatedFlowBuilder(sourceFlow).setMatch(match).build());
+ return Optional.of(new UpdatedFlowBuilder(sourceFlow).setMatch(match).build());
} else {
- return Optional.<Flow>absent();
+ return Optional.empty();
}
}
.build();
if (sourceFlow instanceof AddFlowInput) {
- return Optional.<AddFlowInput>of(new AddFlowInputBuilder(sourceFlow)
+ return Optional.of(new AddFlowInputBuilder(sourceFlow)
.setMatch(match).setInstructions(instructions).build());
} else if (sourceFlow instanceof RemoveFlowInput) {
- return Optional.<RemoveFlowInput>of(new RemoveFlowInputBuilder(sourceFlow)
+ return Optional.of(new RemoveFlowInputBuilder(sourceFlow)
.setMatch(match).setInstructions(instructions).build());
} else if (sourceFlow instanceof UpdatedFlow) {
- return Optional.<UpdatedFlow>of(new UpdatedFlowBuilder(sourceFlow)
+ return Optional.of(new UpdatedFlowBuilder(sourceFlow)
.setMatch(match).setInstructions(instructions).build());
} else {
- return Optional.<Flow>absent();
+ return Optional.empty();
}
}
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<org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action> 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();
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);
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();
}
return targetInstructionList;
}
+ @Override
+ public Class<?> getType() {
+ return Flow.class;
+ }
+
+ @Override
+ public List<FlowModInputBuilder> 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()));
+ }
+ }
}
--- /dev/null
+/*
+ * 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<Action> wrapActionList(List<org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action> actionList) {
+ List<Action> 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;
+ }
+}
* 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.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;
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:
+ * <pre>
+ * {@code
+ * VersionConvertorData data = new VersionConvertorData(version);
+ * Optional<Instructions> salFlowInstruction = ConvertorManager.getInstance().convert(ofFlowInstructions, data);
+ * }
+ * </pre>
+ */
+public final class FlowInstructionResponseConvertor implements ParametrizedConvertor<
+ List<org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instructions.grouping.Instruction>,
+ 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<org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instructions.grouping.Instruction> instructions, OpenflowVersion ofVersion) {
-
+ @Override
+ public Instructions convert(List<org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instructions.grouping.Instruction> source, VersionConvertorData data) {
InstructionsBuilder instructionsBuilder = new InstructionsBuilder();
- List<Instruction> salInstructionList = new ArrayList<Instruction>();
+ List<Instruction> 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<List<org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action>> actions = ConvertorManager.getInstance().convert(
+ final Optional<List<Action>> 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();
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()));
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<List<org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action>> actions = ConvertorManager.getInstance().convert(
+ final Optional<List<Action>> 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();
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<Action> wrapActionList(List<org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action> actionList) {
- List<Action> 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<org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.Action> actionsList, OpenflowVersion ofVersion) {
- InstructionsBuilder instructionsBuilder = new InstructionsBuilder();
-
- List<Instruction> salInstructionList = new ArrayList<Instruction>();
-
- 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<List<org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action>> 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();
}
-
}
--- /dev/null
+/*
+ * 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:
+ * <pre>
+ * {@code
+ * VersionDatapathIdConvertorData data = new VersionDatapathIdConvertorData(version);
+ * data.setDatapathId(datapathId);
+ * Optional<List<FlowAndStatisticsMapList>> salFlowStats = ConvertorManager.getInstance().convert(ofFlowStats, data);
+ * }
+ * </pre>
+ */
+public class FlowStatsResponseConvertor implements ParametrizedConvertor<List<FlowStats>, List<FlowAndStatisticsMapList>, 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<org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.Action> 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<Instruction> salInstructionList = new ArrayList<>();
+
+ ApplyActionsCaseBuilder applyActionsCaseBuilder = new ApplyActionsCaseBuilder();
+ ApplyActionsBuilder applyActionsBuilder = new ApplyActionsBuilder();
+
+ final Optional<List<org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action>> 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<FlowAndStatisticsMapList> convert(List<FlowStats> source, VersionDatapathIdConvertorData data) {
+ final List<FlowAndStatisticsMapList> 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<MatchBuilder> 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<MatchBuilder> matchBuilderOptional = ConvertorManager.getInstance().convert(flowStats.getMatch(), data);
+
+ if (matchBuilderOptional.isPresent()) {
+ final MatchBuilder matchBuilder = matchBuilderOptional.get();
+
+ final AugmentTuple<Match> 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> instructions = ConvertorManager.getInstance().convert(
+ flowStats.getInstruction(), simpleConvertorData);
+
+ salFlowStatsBuilder.setInstructions(instructions.orElse(new InstructionsBuilder()
+ .setInstruction(Collections.emptyList()).build()));
+ }
+
+ result.add(salFlowStatsBuilder.build());
+ }
+
+ return result;
+ }
+}
--- /dev/null
+/*
+ * 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<org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.ApplyActionsCase, Instruction, ActionConvertorData> {
+ 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<Instruction> 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<List<Action>> 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());
+ }
+}
--- /dev/null
+/*
+ * 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<org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.ClearActionsCase, Instruction, ActionConvertorData> {
+ 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<Instruction> 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());
+ }
+}
--- /dev/null
+/*
+ * 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<org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.GoToTableCase, Instruction, ActionConvertorData> {
+ 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<Instruction> 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());
+ }
+}
--- /dev/null
+/*
+ * 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<org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.MeterCase, Instruction, ActionConvertorData> {
+ 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<Instruction> 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());
+ }
+}
--- /dev/null
+/*
+ * 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<org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.WriteActionsCase, Instruction, ActionConvertorData> {
+ 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<Instruction> 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<List<Action>> 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());
+ }
+}
--- /dev/null
+/*
+ * 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<org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.WriteMetadataCase, Instruction, ActionConvertorData> {
+ 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<Instruction> 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());
+ }
+}
-/**
+/*
* Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
*
* This program and the accompanying materials are made available under the
* 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 <E> type of converted match
+ *
+ * @param <E> type of converted match
*/
public interface FlowFlagConvertor<E> extends Convertor<FlowModFlags, E> {
-/**
+/*
* Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
*
* This program and the accompanying materials are made available under the
* 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;
@Override
protected void initMappings(final Map<Short, Convertor<FlowModFlags, ?>> conversions,
- final Map<InjectionKey, ResultInjector<?,?>> injections) {
+ final Map<InjectionKey, ResultInjector<?, ?>> injections) {
FlowFlagReactorMappingFactory.addFlowFlagsConvertors(conversions);
FlowFlagReactorMappingFactory.addFlowFlagsIjectors(injections);
}
-/**
+/*
* Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
*
* This program and the accompanying materials are made available under the
* 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;
/**
* add prepared convertors and injectors into given mappings
+ *
* @see FlowFlagReactor
*/
public class FlowFlagReactorMappingFactory {
// OF-1.3|FlowModFlags --> FlowModInputBuilder
injectionMapping.put(new InjectionKey(OFConstants.OFP_VERSION_1_3, FlowModInputBuilder.class),
new ResultInjector<FlowModFlags, FlowModInputBuilder>() {
- @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<FlowModFlagsV10, FlowModInputBuilder>() {
- @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);
+ }
+ });
}
-/**
+/*
* Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
*
* This program and the accompanying materials are made available under the
* 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<FlowModFlags> {
@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;
}
}
-/**
+/*
* Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
*
* This program and the accompanying materials are made available under the
* 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<FlowModFlagsV10> {
@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;
}
}
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;
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;
protected static final Logger logger = LoggerFactory
.getLogger(MultipartReplyTranslator.class);
- private static FlowStatsResponseConvertor flowStatsConvertor = new FlowStatsResponseConvertor();
-
@Override
public List<DataObject> translate(final SwitchConnectionDistinguisher cookie, final SessionContext sc, final OfHeader msg) {
message.setTransactionId(generateTransactionId(mpReply.getXid()));
MultipartReplyFlowCase caseBody = (MultipartReplyFlowCase)mpReply.getMultipartReplyBody();
MultipartReplyFlow replyBody = caseBody.getMultipartReplyFlow();
- message.setFlowAndStatisticsMapList(flowStatsConvertor.toSALFlowStatsList(replyBody.getFlowStats(),sc.getFeatures().getDatapathId(), ofVersion));
+ final VersionDatapathIdConvertorData data = new VersionDatapathIdConvertorData(sc.getPrimaryConductor().getVersion());
+ data.setDatapathId(sc.getFeatures().getDatapathId());
+
+ final Optional<List<FlowAndStatisticsMapList>> 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;
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;
+++ /dev/null
-/**
- * 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<FlowModInputBuilder> 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<org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action> 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 extends Augmentation<AddFlowInput>> E getAugmentation(final Class<E> 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<? extends DataContainer> getImplementedInterface() {
- return null;
- }
- }
-
-}
import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorManager;\r
import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.data.ActionConvertorData;\r
import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.data.ActionResponseConvertorData;\r
+import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.flow.FlowConvertorUtil;\r
import org.opendaylight.openflowplugin.openflow.md.util.OpenflowPortsUtil;\r
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpVersion;\r
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix;\r
\r
ActionConvertorData data = new ActionConvertorData(OFConstants.OFP_VERSION_1_0);\r
data.setDatapathId(new BigInteger("42"));\r
- if (flow.getMatch() != null && flow.getMatch().getIpMatch() != null) {\r
- data.setIpProtocol(flow.getMatch().getIpMatch().getIpProtocol());\r
- }\r
+ data.setIpProtocol(FlowConvertorUtil.getIpProtocolFromFlow(flow));\r
\r
Optional<List<org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.Action>> actionsOptional =\r
ConvertorManager.getInstance().convert(salActions, data);\r
import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorManager;\r
import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.data.ActionConvertorData;\r
import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.data.ActionResponseConvertorData;\r
+import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.flow.FlowConvertorUtil;\r
import org.opendaylight.openflowplugin.openflow.md.util.OpenflowPortsUtil;\r
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix;\r
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Prefix;\r
\r
ActionConvertorData data = new ActionConvertorData(OFConstants.OFP_VERSION_1_3);\r
data.setDatapathId(new BigInteger("42"));\r
-\r
- if (flow.getMatch() != null && flow.getMatch().getIpMatch() != null) {\r
- data.setIpProtocol(flow.getMatch().getIpMatch().getIpProtocol());\r
- }\r
+ data.setIpProtocol(FlowConvertorUtil.getIpProtocolFromFlow(flow));\r
\r
Optional<List<Action>> actionsOptional = ConvertorManager.getInstance().convert(salActions, data);\r
List<Action> actions = actionsOptional.orElse(Collections.emptyList());\r
* and is available at http://www.eclipse.org/legal/epl-v10.html\r
*/\r
\r
-package org.opendaylight.openflowplugin.openflow.md.core.sal.convertor;\r
+package org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.flow;\r
\r
import java.math.BigInteger;\r
import java.util.ArrayList;\r
+import java.util.Collections;\r
import java.util.List;\r
+import java.util.Optional;\r
import org.junit.Assert;\r
import org.junit.Test;\r
-import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;\r
+import org.opendaylight.openflowplugin.api.OFConstants;\r
+import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorManager;\r
+import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.data.VersionDatapathIdConvertorData;\r
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Uri;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetVlanIdActionCaseBuilder;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.vlan.id.action._case.SetVlanIdActionBuilder;\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionBuilder;\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowInput;\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowInputBuilder;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.FlowTableRef;\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.RemoveFlowInput;\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.RemoveFlowInputBuilder;\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.flow.update.UpdatedFlow;\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.flow.update.UpdatedFlowBuilder;\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.Flow;\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowCookie;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowRef;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Instructions;\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.InstructionsBuilder;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Match;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder;\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.ApplyActionsCaseBuilder;\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.ClearActionsCaseBuilder;\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.GoToTableCaseBuilder;\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.write.metadata._case.WriteMetadataBuilder;\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.Instruction;\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.InstructionBuilder;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRef;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.EtherType;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanId;\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.MeterId;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ethernet.match.fields.EthernetTypeBuilder;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.EthernetMatch;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.EthernetMatchBuilder;\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instruction.grouping.instruction.choice.ApplyActionsCase;\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instruction.grouping.instruction.choice.GotoTableCase;\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instruction.grouping.instruction.choice.MeterCase;\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.FlowModCommand;\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.FlowModFlags;\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowModInputBuilder;\r
+import org.opendaylight.yangtools.yang.binding.Augmentation;\r
+import org.opendaylight.yangtools.yang.binding.DataContainer;\r
\r
/**\r
* @author michal.polkorab\r
public class FlowConvertorTest {\r
\r
/**\r
- * Tests {@link FlowConvertor#toFlowModInputs(Flow, short, BigInteger)}\r
+ * 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)} }\r
*/\r
@Test\r
public void test() {\r
flowBuilder.setMatch(null);\r
RemoveFlowInput flow = flowBuilder.build();\r
\r
- List<FlowModInputBuilder> flowMod = FlowConvertor\r
- .toFlowModInputs(flow, EncodeConstants.OF13_VERSION_ID, new BigInteger("42"));\r
+ VersionDatapathIdConvertorData data = new VersionDatapathIdConvertorData(OFConstants.OFP_VERSION_1_3);\r
+ data.setDatapathId(new BigInteger("42"));\r
+\r
+ List<FlowModInputBuilder> flowMod = convert(flow, data);\r
\r
Assert.assertEquals("Wrong version", 4, flowMod.get(0).getVersion().intValue());\r
Assert.assertEquals("Wrong cookie", 4, flowMod.get(0).getCookie().intValue());\r
}\r
\r
/**\r
- * Tests {@link FlowConvertor#toFlowModInputs(Flow, short, BigInteger)}\r
+ * 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)} }\r
*/\r
@Test\r
public void testOnlyModifyStrictCommand() {\r
flowBuilder.setStrict(true);\r
UpdatedFlow flow = flowBuilder.build();\r
\r
- List<FlowModInputBuilder> flowMod = FlowConvertor\r
- .toFlowModInputs(flow, EncodeConstants.OF10_VERSION_ID, new BigInteger("42"));\r
+ VersionDatapathIdConvertorData data = new VersionDatapathIdConvertorData(OFConstants.OFP_VERSION_1_0);\r
+ data.setDatapathId(new BigInteger("42"));\r
+\r
+ List<FlowModInputBuilder> flowMod = convert(flow, data);\r
\r
Assert.assertEquals("Wrong version", 1, flowMod.get(0).getVersion().intValue());\r
Assert.assertEquals("Wrong command", FlowModCommand.OFPFCADD, flowMod.get(0).getCommand());\r
}\r
\r
/**\r
- * Tests {@link FlowConvertor#toFlowModInputs(Flow, short, BigInteger)}\r
+ * 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)} }\r
*/\r
@Test\r
public void testInstructionsTranslation() {\r
flowBuilder.setInstructions(instructionsBuilder.build());\r
AddFlowInput flow = flowBuilder.build();\r
\r
- List<FlowModInputBuilder> flowMod = FlowConvertor\r
- .toFlowModInputs(flow, EncodeConstants.OF10_VERSION_ID, new BigInteger("42"));\r
+ VersionDatapathIdConvertorData data = new VersionDatapathIdConvertorData(OFConstants.OFP_VERSION_1_0);\r
+ data.setDatapathId(new BigInteger("42"));\r
+ List<FlowModInputBuilder> flowMod = convert(flow, data);\r
\r
Assert.assertEquals("Wrong version", 1, flowMod.get(0).getVersion().intValue());\r
Assert.assertEquals("Wrong command", FlowModCommand.OFPFCADD, flowMod.get(0).getCommand());\r
MeterCase meterCase = (MeterCase) instruction.getInstructionChoice();\r
Assert.assertEquals("Wrong meter id", 5, meterCase.getMeter().getMeterId().intValue());\r
}\r
+\r
+ @Test\r
+ public void testCloneAndAugmentFlowWithSetVlanId() {\r
+ MockFlow mockFlow = new MockFlow();\r
+ Action action1 = createAction(\r
+ new SetVlanIdActionCaseBuilder().setSetVlanIdAction(\r
+ new SetVlanIdActionBuilder().setVlanId(new VlanId(10)).build())\r
+ .build(),\r
+ 0);\r
+\r
+ mockFlow.setMatch(new MatchBuilder().setEthernetMatch(createEthernetMatch()).build());\r
+ mockFlow.setInstructions(toApplyInstruction(Collections.singletonList(action1)));\r
+\r
+ VersionDatapathIdConvertorData data = new VersionDatapathIdConvertorData(OFConstants.OFP_VERSION_1_3);\r
+ data.setDatapathId(BigInteger.ONE);\r
+\r
+ List<FlowModInputBuilder> flowModInputBuilders = convert(mockFlow, data);\r
+\r
+ Assert.assertEquals(2, flowModInputBuilders.size());\r
+\r
+ }\r
+\r
+ private List<FlowModInputBuilder> convert(Flow flow, VersionDatapathIdConvertorData data) {\r
+ Optional<List<FlowModInputBuilder>> flowModOptional = ConvertorManager.getInstance().convert(flow, data);\r
+ Assert.assertTrue("Flow convertor not found", flowModOptional.isPresent());\r
+ return flowModOptional.get();\r
+ }\r
+\r
+ private static Action createAction(final org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action actionCase,\r
+ final int order) {\r
+ Action action = new ActionBuilder().setOrder(order).setAction(actionCase).build();\r
+ return action;\r
+ }\r
+\r
+ private static EthernetMatch createEthernetMatch() {\r
+ EthernetMatchBuilder ethernetMatchBuilder = new EthernetMatchBuilder();\r
+ ethernetMatchBuilder.setEthernetType(new EthernetTypeBuilder().setType(new EtherType(33024L)).build());\r
+ return ethernetMatchBuilder.build();\r
+ }\r
+\r
+ private static Instructions toApplyInstruction(\r
+ final List<org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action> actions) {\r
+ return new InstructionsBuilder()\r
+ .setInstruction(\r
+ Collections.singletonList(\r
+ new InstructionBuilder()\r
+ .setOrder(0)\r
+ .setInstruction(\r
+ new ApplyActionsCaseBuilder()\r
+ .setApplyActions((new ApplyActionsBuilder()).setAction(actions).build())\r
+ .build()\r
+ ).build())\r
+ ).build();\r
+ }\r
+\r
+ private static class MockFlow implements AddFlowInput {\r
+ private Instructions instructions;\r
+ private Match match;\r
+\r
+ public void setInstructions(final Instructions instructions) {\r
+ this.instructions = instructions;\r
+ }\r
+\r
+ public void setMatch(final Match match) {\r
+ this.match = match;\r
+ }\r
+\r
+\r
+ @Override\r
+ public FlowRef getFlowRef() {\r
+ return null;\r
+ }\r
+\r
+ @Override\r
+ public <E extends Augmentation<AddFlowInput>> E getAugmentation(final Class<E> augmentationType) {\r
+ return null;\r
+ }\r
+\r
+ @Override\r
+ public FlowTableRef getFlowTable() {\r
+ return null;\r
+ }\r
+\r
+ @Override\r
+ public Match getMatch() {\r
+ return match;\r
+ }\r
+\r
+ @Override\r
+ public Instructions getInstructions() {\r
+ return instructions;\r
+ }\r
+\r
+ @Override\r
+ public String getContainerName() {\r
+ return null;\r
+ }\r
+\r
+ @Override\r
+ public FlowCookie getCookieMask() {\r
+ return null;\r
+ }\r
+\r
+ @Override\r
+ public Long getBufferId() {\r
+ return null;\r
+ }\r
+\r
+ @Override\r
+ public BigInteger getOutPort() {\r
+ return null;\r
+ }\r
+\r
+ @Override\r
+ public Long getOutGroup() {\r
+ return null;\r
+ }\r
+\r
+ @Override\r
+ public org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowModFlags getFlags() {\r
+ return null;\r
+ }\r
+\r
+ @Override\r
+ public String getFlowName() {\r
+ return null;\r
+ }\r
+\r
+ @Override\r
+ public Boolean isInstallHw() {\r
+ return null;\r
+ }\r
+\r
+ @Override\r
+ public Boolean isBarrier() {\r
+ return null;\r
+ }\r
+\r
+ @Override\r
+ public Boolean isStrict() {\r
+ return null;\r
+ }\r
+\r
+ @Override\r
+ public Integer getPriority() {\r
+ return null;\r
+ }\r
+\r
+ @Override\r
+ public Integer getIdleTimeout() {\r
+ return null;\r
+ }\r
+\r
+ @Override\r
+ public Integer getHardTimeout() {\r
+ return null;\r
+ }\r
+\r
+ @Override\r
+ public FlowCookie getCookie() {\r
+ return null;\r
+ }\r
+\r
+ @Override\r
+ public Short getTableId() {\r
+ return null;\r
+ }\r
+\r
+ @Override\r
+ public NodeRef getNode() {\r
+ return null;\r
+ }\r
+\r
+ @Override\r
+ public Uri getTransactionUri() {\r
+ return null;\r
+ }\r
+\r
+ @Override\r
+ public Class<? extends DataContainer> getImplementedInterface() {\r
+ return null;\r
+ }\r
+ }\r
}
\ No newline at end of file
* 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;
/**
* 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() {
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() {
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());
instructionsList.add(instructionBuilder.build());
}
- instructions = OFToMDSalFlowConvertor.toSALInstruction(instructionsList, OpenflowVersion.OF13);
+ instructions = convert(instructionsList, data);
assertNotNull(instructions);
assertEquals(PRESET_COUNT, instructions.getInstruction().size());
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());
instructionsList.add(instructionBuilder.build());
}
- instructions = OFToMDSalFlowConvertor.toSALInstruction(instructionsList, OpenflowVersion.OF13);
+ instructions = convert(instructionsList, data);
assertNotNull(instructions);
assertEquals(PRESET_COUNT, instructions.getInstruction().size());
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);
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<Instruction> instructionsList, VersionConvertorData data) {
+ Optional<Instructions> 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
}
* 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;