From 9c30b963448f71f90d1118a5ad2d55829e1fe451 Mon Sep 17 00:00:00 2001 From: Tomas Slusny Date: Mon, 27 Jun 2016 14:24:11 +0200 Subject: [PATCH] Bug 5540 - TableFeaturesConvertor - Reworked TableFeaturesConvertor to use new ConvertorManager design - Updated tests and usage of TableFeaturesConvertor accordingly Change-Id: Ic2430412edac4cc0658f1fa7ccdecb5ebf937eef Signed-off-by: Tomas Slusny --- .../impl/services/SalTableServiceImpl.java | 10 +- .../md/core/sal/OFRpcTaskFactory.java | 9 +- .../core/sal/convertor/ConvertorManager.java | 1 + .../sal/convertor/TableFeaturesConvertor.java | 220 ++++++++++-------- .../convertor/TableFeaturesConvertorTest.java | 19 +- 5 files changed, 149 insertions(+), 110 deletions(-) diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/SalTableServiceImpl.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/SalTableServiceImpl.java index bd38f2836a..86d1e78922 100644 --- a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/SalTableServiceImpl.java +++ b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/SalTableServiceImpl.java @@ -13,14 +13,16 @@ import com.google.common.util.concurrent.ListenableFuture; import com.google.common.util.concurrent.SettableFuture; import java.math.BigInteger; import java.util.ArrayList; +import java.util.Collections; import java.util.List; +import java.util.Optional; import java.util.concurrent.Future; import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext; import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack; import org.opendaylight.openflowplugin.api.openflow.device.TxFacade; import org.opendaylight.openflowplugin.api.openflow.device.Xid; -import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.TableFeaturesConvertor; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorManager; import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.TableFeaturesReplyConvertor; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.transaction.rev150304.TransactionId; @@ -166,9 +168,9 @@ public final class SalTableServiceImpl extends AbstractMultipartService ofTableFeatureList = TableFeaturesConvertor.toTableFeaturesRequest(input - .getUpdatedTable()); - requestBuilder.setTableFeatures(ofTableFeatureList); + + final Optional> ofTableFeatureList = ConvertorManager.getInstance().convert(input.getUpdatedTable()); + requestBuilder.setTableFeatures(ofTableFeatureList.orElse(Collections.emptyList())); caseBuilder.setMultipartRequestTableFeatures(requestBuilder.build()); // Set request body to main multipart request diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/OFRpcTaskFactory.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/OFRpcTaskFactory.java index 774dce40b4..b82abb2c42 100644 --- a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/OFRpcTaskFactory.java +++ b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/OFRpcTaskFactory.java @@ -17,6 +17,7 @@ import com.google.common.util.concurrent.ListenableFuture; import com.google.common.util.concurrent.SettableFuture; import java.math.BigInteger; import java.util.ArrayList; +import java.util.Collections; import java.util.List; import java.util.concurrent.Future; import org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction; @@ -27,11 +28,11 @@ import org.opendaylight.openflowplugin.api.OFConstants; import org.opendaylight.openflowplugin.api.openflow.md.core.SwitchConnectionDistinguisher; 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; -import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.TableFeaturesConvertor; import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.match.MatchReactor; import org.opendaylight.openflowplugin.openflow.md.util.FlowCreatorUtil; import org.opendaylight.openflowplugin.openflow.md.util.InventoryDataServiceUtil; @@ -2123,9 +2124,9 @@ public abstract class OFRpcTaskFactory { MultipartRequestTableFeaturesCaseBuilder caseBuilder = new MultipartRequestTableFeaturesCaseBuilder(); MultipartRequestTableFeaturesBuilder requestBuilder = new MultipartRequestTableFeaturesBuilder(); - List ofTableFeatureList = TableFeaturesConvertor - .toTableFeaturesRequest(input.getUpdatedTable()); - requestBuilder.setTableFeatures(ofTableFeatureList); + + final java.util.Optional> ofTableFeatureList = ConvertorManager.getInstance().convert(input.getUpdatedTable()); + requestBuilder.setTableFeatures(ofTableFeatureList.orElse(Collections.emptyList())); caseBuilder.setMultipartRequestTableFeatures(requestBuilder.build()); // Set request body to main multipart request diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/ConvertorManager.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/ConvertorManager.java index db46143c16..ef84bd6807 100644 --- a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/ConvertorManager.java +++ b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/ConvertorManager.java @@ -32,6 +32,7 @@ public class ConvertorManager { static { INSTANCE = new ConvertorManager(); // All convertors are registered here + INSTANCE.registerConvertor(new TableFeaturesConvertor()); } // Actual convertor keys diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/TableFeaturesConvertor.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/TableFeaturesConvertor.java index 111fafde91..d5699ed0ad 100644 --- a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/TableFeaturesConvertor.java +++ b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/TableFeaturesConvertor.java @@ -1,4 +1,4 @@ -/** +/* * Copyright (c) 2013 Ericsson. and others. All rights reserved. * * This program and the accompanying materials are made available under the @@ -15,6 +15,7 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Map; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.Convertor; import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.OrderComparator; import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.CopyTtlInCase; import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.CopyTtlOutCase; @@ -147,43 +148,78 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** - * Utility class for converting a MD-SAL Table features into the OF library table - * features. + * Converts a MD-SAL table features into the OF library table features. + * + * Example usage: + *
+ * {@code
+ * Optional> ofFeatures = ConvertorManager.getInstance().convert(salTableFeatures);
+ * }
+ * 
*/ -public class TableFeaturesConvertor { +public class TableFeaturesConvertor implements Convertor< + org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.TableFeatures, + List> { + private static final Logger LOG = LoggerFactory.getLogger(TableFeaturesConvertor.class); private static final Ordering TABLE_FEATURE_PROPS_ORDERING = Ordering.from(OrderComparator.build()); + private static final Map, Class> SAL_TO_OF_TABLE_FEATURES; - private TableFeaturesConvertor() { - //hiding implicit construcotr - } - - public static List toTableFeaturesRequest( - final org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.TableFeatures salTableFeaturesList) { - List ofTableFeaturesList = new ArrayList<>(); - TableFeaturesBuilder ofTableFeatures = new TableFeaturesBuilder(); - for (org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.features.TableFeatures salTableFeatures : salTableFeaturesList - .getTableFeatures()) { - ofTableFeatures.setTableId(salTableFeatures.getTableId()); - ofTableFeatures.setName(salTableFeatures.getName()); - ofTableFeatures.setMetadataMatch(salTableFeatures.getMetadataMatch()); - ofTableFeatures.setMetadataWrite(salTableFeatures.getMetadataWrite()); - ofTableFeatures.setMaxEntries(salTableFeatures.getMaxEntries()); - if (salTableFeatures.getConfig() != null) { - ofTableFeatures.setConfig(new TableConfig(salTableFeatures.getConfig().isDEPRECATEDMASK())); - } - ofTableFeatures.setTableFeatureProperties(toTableProperties(salTableFeatures.getTableProperties())); - ofTableFeaturesList.add(ofTableFeatures.build()); - } - return ofTableFeaturesList; + static { + Builder, Class> builder = ImmutableMap.builder(); + builder.put(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.ArpOp.class, ArpOp.class); + builder.put(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.ArpSha.class, ArpSha.class); + builder.put(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.ArpSpa.class, ArpSpa.class); + builder.put(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.ArpTha.class, ArpTha.class); + builder.put(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.ArpTpa.class, ArpTpa.class); + builder.put(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.EthDst.class, EthDst.class); + builder.put(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.EthSrc.class, EthSrc.class); + builder.put(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.EthType.class, EthType.class); + builder.put(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.Icmpv4Code.class, Icmpv4Code.class); + builder.put(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.Icmpv4Type.class, Icmpv4Type.class); + builder.put(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.Icmpv6Code.class, Icmpv6Code.class); + builder.put(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.Icmpv6Type.class, Icmpv6Type.class); + builder.put(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.InPhyPort.class, InPhyPort.class); + builder.put(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.InPort.class, InPort.class); + builder.put(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.IpDscp.class, IpDscp.class); + builder.put(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.IpEcn.class, IpEcn.class); + builder.put(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.IpProto.class, IpProto.class); + builder.put(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.Ipv4Dst.class, Ipv4Dst.class); + builder.put(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.Ipv4Src.class, Ipv4Src.class); + builder.put(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.Ipv6Dst.class, Ipv6Dst.class); + builder.put(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.Ipv6Exthdr.class, Ipv6Exthdr.class); + builder.put(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.Ipv6Flabel.class, Ipv6Flabel.class); + builder.put(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.Ipv6NdSll.class, Ipv6NdSll.class); + builder.put(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.Ipv6NdTarget.class, Ipv6NdTarget.class); + builder.put(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.Ipv6NdTll.class, Ipv6NdTll.class); + builder.put(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.Ipv6Src.class, Ipv6Src.class); + builder.put(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.Metadata.class, Metadata.class); + builder.put(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.MplsBos.class, MplsBos.class); + builder.put(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.MplsLabel.class, MplsLabel.class); + builder.put(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.MplsTc.class, MplsTc.class); + builder.put(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.PbbIsid.class, PbbIsid.class); + builder.put(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.SctpDst.class, SctpDst.class); + builder.put(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.SctpSrc.class, SctpSrc.class); + builder.put(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.TcpDst.class, TcpDst.class); + builder.put(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.TcpSrc.class, TcpSrc.class); + builder.put(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.TunnelId.class, TunnelId.class); + builder.put(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.UdpDst.class, UdpDst.class); + builder.put(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.UdpSrc.class, UdpSrc.class); + builder.put(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.VlanPcp.class, VlanPcp.class); + builder.put(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.VlanVid.class, VlanVid.class); + builder.put(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.TunnelIpv4Dst.class, Ipv4Dst.class); + builder.put(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.TunnelIpv4Src.class, Ipv4Src.class); + builder.put(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.TcpFlags.class, TcpFlags.class); + SAL_TO_OF_TABLE_FEATURES = builder.build(); } private static List toTableProperties( final org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.features.table.features.TableProperties tableProperties) { if (tableProperties == null) { - return Collections.emptyList(); + return Collections.emptyList(); } + List ofTablePropertiesList = new ArrayList<>(); List @@ -196,7 +232,8 @@ public class TableFeaturesConvertor { org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.TableFeaturePropType propType = property .getTableFeaturePropType(); - setTableFeatureProperty(propType, propBuilder); + setTableFeatureProperty(propType); + if (propType instanceof Instructions) { setTableFeatureProperty((Instructions) propType, propBuilder); } else if (propType instanceof InstructionsMiss) { @@ -226,13 +263,15 @@ public class TableFeaturesConvertor { } else if (propType instanceof ApplySetfieldMiss) { setTableFeatureProperty((ApplySetfieldMiss) propType, propBuilder); } - // Experimenter and Experimeneter miss Table features are unhandled + + // Experimenter and Experimenter miss Table features are unhandled ofTablePropertiesList.add(propBuilder.build()); } + return ofTablePropertiesList; } - private static void setTableFeatureProperty(final TableFeaturePropType propType, final TableFeaturePropertiesBuilder propBuilder) { + private static void setTableFeatureProperty(final TableFeaturePropType propType) { LOG.debug("Unknown TableFeaturePropType [{}]", propType.getClass()); } @@ -243,10 +282,11 @@ public class TableFeaturesConvertor { if (null != applySetfieldMiss) { setFieldMatch = applySetfieldMiss.getSetFieldMatch(); } + setSetFieldTableFeatureProperty( propBuilder, TableFeaturesPropType.OFPTFPTAPPLYSETFIELDMISS, - ((setFieldMatch == null) ? new ArrayList() + ((setFieldMatch == null) ? new ArrayList<>() : setFieldMatch)); } @@ -257,10 +297,11 @@ public class TableFeaturesConvertor { if (null != applySetfield) { setFieldMatch = applySetfield.getSetFieldMatch(); } + setSetFieldTableFeatureProperty( propBuilder, TableFeaturesPropType.OFPTFPTAPPLYSETFIELD, - ((setFieldMatch == null) ? new ArrayList() + ((setFieldMatch == null) ? new ArrayList<>() : setFieldMatch)); } @@ -271,10 +312,11 @@ public class TableFeaturesConvertor { if (null != writeSetfieldMiss) { setFieldMatch = writeSetfieldMiss.getSetFieldMatch(); } + setSetFieldTableFeatureProperty( propBuilder, TableFeaturesPropType.OFPTFPTWRITESETFIELDMISS, - ((setFieldMatch == null) ? new ArrayList() + ((setFieldMatch == null) ? new ArrayList<>() : setFieldMatch)); } @@ -289,7 +331,7 @@ public class TableFeaturesConvertor { setSetFieldTableFeatureProperty( propBuilder, TableFeaturesPropType.OFPTFPTWRITESETFIELD, - ((setFieldMatch == null) ? new ArrayList() + ((setFieldMatch == null) ? new ArrayList<>() : setFieldMatch)); } @@ -304,7 +346,7 @@ public class TableFeaturesConvertor { setSetFieldTableFeatureProperty( propBuilder, TableFeaturesPropType.OFPTFPTWILDCARDS, - ((setFieldMatch == null) ? new ArrayList() + ((setFieldMatch == null) ? new ArrayList<>() : setFieldMatch)); } @@ -319,7 +361,7 @@ public class TableFeaturesConvertor { setSetFieldTableFeatureProperty( propBuilder, TableFeaturesPropType.OFPTFPTMATCH, - ((setFieldMatch == null) ? new ArrayList() + ((setFieldMatch == null) ? new ArrayList<>() : setFieldMatch)); } @@ -329,7 +371,7 @@ public class TableFeaturesConvertor { setActionTableFeatureProperty( propBuilder, TableFeaturesPropType.OFPTFPTAPPLYACTIONSMISS, - ((applyActionsMiss == null) ? new ArrayList() + ((applyActionsMiss == null) ? new ArrayList<>() : applyActionsMiss.getAction())); } @@ -338,7 +380,7 @@ public class TableFeaturesConvertor { setActionTableFeatureProperty( propBuilder, TableFeaturesPropType.OFPTFPTAPPLYACTIONS, - ((applyActions == null) ? new ArrayList() + ((applyActions == null) ? new ArrayList<>() : applyActions.getAction())); } @@ -347,7 +389,7 @@ public class TableFeaturesConvertor { setActionTableFeatureProperty( propBuilder, TableFeaturesPropType.OFPTFPTWRITEACTIONSMISS, - ((writeActionsMiss == null) ? new ArrayList() + ((writeActionsMiss == null) ? new ArrayList<>() : writeActionsMiss.getAction())); } @@ -356,7 +398,7 @@ public class TableFeaturesConvertor { setActionTableFeatureProperty( propBuilder, TableFeaturesPropType.OFPTFPTWRITEACTIONS, - ((writeActions == null) ? new ArrayList() + ((writeActions == null) ? new ArrayList<>() : writeActions.getAction())); } @@ -364,28 +406,28 @@ public class TableFeaturesConvertor { TablesMiss tables = propType .getTablesMiss(); setNextTableFeatureProperty(propBuilder, TableFeaturesPropType.OFPTFPTNEXTTABLESMISS, - (tables == null) ? new ArrayList() : tables.getTableIds()); + (tables == null) ? new ArrayList<>() : tables.getTableIds()); } private static void setTableFeatureProperty(final NextTable propType, final TableFeaturePropertiesBuilder propBuilder) { org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.next.table.Tables tables = propType .getTables(); setNextTableFeatureProperty(propBuilder, TableFeaturesPropType.OFPTFPTNEXTTABLES, - (tables == null) ? new ArrayList() : tables.getTableIds()); + (tables == null) ? new ArrayList<>() : tables.getTableIds()); } private static void setTableFeatureProperty(final InstructionsMiss propType, final TableFeaturePropertiesBuilder propBuilder) { org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.instructions.miss.InstructionsMiss instructions = propType .getInstructionsMiss(); setInstructionTableFeatureProperty(propBuilder, TableFeaturesPropType.OFPTFPTINSTRUCTIONSMISS, - (instructions == null) ? new ArrayList() : instructions.getInstruction()); + (instructions == null) ? new ArrayList<>() : instructions.getInstruction()); } private static void setTableFeatureProperty(final Instructions propType, final TableFeaturePropertiesBuilder propBuilder) { org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.instructions.Instructions instructions = propType .getInstructions(); setInstructionTableFeatureProperty(propBuilder, TableFeaturesPropType.OFPTFPTINSTRUCTIONS, - (instructions == null) ? new ArrayList() : instructions.getInstruction()); + (instructions == null) ? new ArrayList<>() : instructions.getInstruction()); } private static void setInstructionTableFeatureProperty(final TableFeaturePropertiesBuilder builder, @@ -397,6 +439,7 @@ public class TableFeaturesConvertor { org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.Instruction instruction = currInstruction .getInstruction(); + if (instruction instanceof GoToTableCase) { GotoTableCaseBuilder goToTableCaseBuilder = new GotoTableCaseBuilder(); instructionType.setInstructionChoice(goToTableCaseBuilder.build()); @@ -416,9 +459,11 @@ public class TableFeaturesConvertor { MeterCaseBuilder meterCaseBuilder = new MeterCaseBuilder(); instructionType.setInstructionChoice(meterCaseBuilder.build()); } - // TODO: Experimeneter instructions are unhandled + + // TODO: Experimenter instructions are unhandled instructionTypeList.add(instructionType.build()); } + InstructionRelatedTableFeaturePropertyBuilder propBuilder = new InstructionRelatedTableFeaturePropertyBuilder(); propBuilder.setInstruction(instructionTypeList); builder.setType(type); @@ -434,6 +479,7 @@ public class TableFeaturesConvertor { nextTableId.setTableId(tableId); nextTableIdsList.add(nextTableId.build()); } + NextTableRelatedTableFeaturePropertyBuilder propBuilder = new NextTableRelatedTableFeaturePropertyBuilder(); propBuilder.setNextTableIds(nextTableIdsList); builder.setType(type); @@ -450,6 +496,7 @@ public class TableFeaturesConvertor { org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action actionType = currAction .getAction(); ActionBuilder actionBuilder = new ActionBuilder(); + if (actionType instanceof OutputActionCase) { OutputActionCaseBuilder outputActionCaseBuilder = new OutputActionCaseBuilder(); actionBuilder.setActionChoice(outputActionCaseBuilder.build()); @@ -499,6 +546,7 @@ public class TableFeaturesConvertor { PopPbbCaseBuilder popPbbCaseBuilder = new PopPbbCaseBuilder(); actionBuilder.setActionChoice(popPbbCaseBuilder.build()); } + // Experimenter action is unhandled actionList.add(actionBuilder.build()); } @@ -509,56 +557,6 @@ public class TableFeaturesConvertor { builder.addAugmentation(ActionRelatedTableFeatureProperty.class, propBuilder.build()); } - private static final Map, Class> SAL_TO_OF_TABLE_FEATURES; - - static { - Builder, Class> builder = ImmutableMap.builder(); - builder.put(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.ArpOp.class, ArpOp.class); - builder.put(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.ArpSha.class, ArpSha.class); - builder.put(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.ArpSpa.class, ArpSpa.class); - builder.put(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.ArpTha.class, ArpTha.class); - builder.put(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.ArpTpa.class, ArpTpa.class); - builder.put(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.EthDst.class, EthDst.class); - builder.put(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.EthSrc.class, EthSrc.class); - builder.put(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.EthType.class, EthType.class); - builder.put(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.Icmpv4Code.class, Icmpv4Code.class); - builder.put(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.Icmpv4Type.class, Icmpv4Type.class); - builder.put(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.Icmpv6Code.class, Icmpv6Code.class); - builder.put(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.Icmpv6Type.class, Icmpv6Type.class); - builder.put(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.InPhyPort.class, InPhyPort.class); - builder.put(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.InPort.class, InPort.class); - builder.put(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.IpDscp.class, IpDscp.class); - builder.put(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.IpEcn.class, IpEcn.class); - builder.put(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.IpProto.class, IpProto.class); - builder.put(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.Ipv4Dst.class, Ipv4Dst.class); - builder.put(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.Ipv4Src.class, Ipv4Src.class); - builder.put(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.Ipv6Dst.class, Ipv6Dst.class); - builder.put(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.Ipv6Exthdr.class, Ipv6Exthdr.class); - builder.put(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.Ipv6Flabel.class, Ipv6Flabel.class); - builder.put(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.Ipv6NdSll.class, Ipv6NdSll.class); - builder.put(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.Ipv6NdTarget.class, Ipv6NdTarget.class); - builder.put(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.Ipv6NdTll.class, Ipv6NdTll.class); - builder.put(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.Ipv6Src.class, Ipv6Src.class); - builder.put(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.Metadata.class, Metadata.class); - builder.put(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.MplsBos.class, MplsBos.class); - builder.put(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.MplsLabel.class, MplsLabel.class); - builder.put(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.MplsTc.class, MplsTc.class); - builder.put(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.PbbIsid.class, PbbIsid.class); - builder.put(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.SctpDst.class, SctpDst.class); - builder.put(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.SctpSrc.class, SctpSrc.class); - builder.put(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.TcpDst.class, TcpDst.class); - builder.put(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.TcpSrc.class, TcpSrc.class); - builder.put(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.TunnelId.class, TunnelId.class); - builder.put(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.UdpDst.class, UdpDst.class); - builder.put(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.UdpSrc.class, UdpSrc.class); - builder.put(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.VlanPcp.class, VlanPcp.class); - builder.put(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.VlanVid.class, VlanVid.class); - builder.put(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.TunnelIpv4Dst.class, Ipv4Dst.class); - builder.put(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.TunnelIpv4Src.class, Ipv4Src.class); - builder.put(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.TcpFlags.class, TcpFlags.class); - SAL_TO_OF_TABLE_FEATURES = builder.build(); - } - private static void setSetFieldTableFeatureProperty( final TableFeaturePropertiesBuilder builder, final TableFeaturesPropType type, @@ -569,13 +567,12 @@ public class TableFeaturesConvertor { Class currMatchType = currMatch .getMatchType(); MatchEntryBuilder matchEntryBuilder = new MatchEntryBuilder(); - Class ofTableFeatureClass = SAL_TO_OF_TABLE_FEATURES.get(currMatchType); setMatchEntry(matchEntryBuilder, ofTableFeatureClass, currMatch.isHasMask()); - matchEntriesList.add(matchEntryBuilder.build()); } + OxmRelatedTableFeaturePropertyBuilder propBuilder = new OxmRelatedTableFeaturePropertyBuilder(); propBuilder.setMatchEntry(matchEntriesList); builder.setType(type); @@ -593,4 +590,33 @@ public class TableFeaturesConvertor { builder.setOxmMatchField(field); builder.setHasMask(hasMask); } + + @Override + public Class getType() { + return org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.TableFeatures.class; + } + + @Override + public List convert(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.TableFeatures source) { + List ofTableFeaturesList = new ArrayList<>(); + TableFeaturesBuilder ofTableFeatures = new TableFeaturesBuilder(); + + for (org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.features.TableFeatures salTableFeatures : source + .getTableFeatures()) { + ofTableFeatures.setTableId(salTableFeatures.getTableId()); + ofTableFeatures.setName(salTableFeatures.getName()); + ofTableFeatures.setMetadataMatch(salTableFeatures.getMetadataMatch()); + ofTableFeatures.setMetadataWrite(salTableFeatures.getMetadataWrite()); + ofTableFeatures.setMaxEntries(salTableFeatures.getMaxEntries()); + + if (salTableFeatures.getConfig() != null) { + ofTableFeatures.setConfig(new TableConfig(salTableFeatures.getConfig().isDEPRECATEDMASK())); + } + + ofTableFeatures.setTableFeatureProperties(toTableProperties(salTableFeatures.getTableProperties())); + ofTableFeaturesList.add(ofTableFeatures.build()); + } + + return ofTableFeaturesList; + } } diff --git a/openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/TableFeaturesConvertorTest.java b/openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/TableFeaturesConvertorTest.java index 5e8a0f8272..fb3c14babb 100644 --- a/openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/TableFeaturesConvertorTest.java +++ b/openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/TableFeaturesConvertorTest.java @@ -9,12 +9,15 @@ package org.opendaylight.openflowplugin.openflow.md.core.sal.convertor; import static org.mockito.Mockito.when; + import java.math.BigInteger; import java.util.ArrayList; +import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Map.Entry; +import java.util.Optional; import junit.framework.TestCase; import org.junit.Before; import org.junit.Test; @@ -72,6 +75,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.WildcardsBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.WriteActions; import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.WriteActionsBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.WriteActionsMiss; import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.WriteActionsMissBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.WriteSetfield; import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.WriteSetfieldBuilder; @@ -277,10 +281,10 @@ public class TableFeaturesConvertorTest extends TestCase { augmentationsMap.put(NextTableMiss.class, nextTableMissBuilder.build()); WriteActionsBuilder writeActionsBuilder = new WriteActionsBuilder(); - augmentationsMap.put(NextTableMiss.class, writeActionsBuilder.build()); + augmentationsMap.put(WriteActions.class, writeActionsBuilder.build()); WriteActionsMissBuilder writeActionsMissBuilder = new WriteActionsMissBuilder(); - augmentationsMap.put(WriteActions.class, writeActionsMissBuilder.build()); + augmentationsMap.put(WriteActionsMiss.class, writeActionsMissBuilder.build()); ApplyActionsBuilder applyActionsBuilder = new ApplyActionsBuilder(); augmentationsMap.put(ApplyActions.class, applyActionsBuilder.build()); @@ -315,7 +319,7 @@ public class TableFeaturesConvertorTest extends TestCase { @Test /** - * Basic functionality test method for {@link org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.TableFeaturesConvertor#toTableFeaturesRequest(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.TableFeatures)} + * Basic functionality test method for {@link TableFeaturesConvertor#toTableFeaturesRequest(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.TableFeatures)} */ public void testToTableFeaturesRequest() throws Exception { List tableFeaturesList = new ArrayList<>(); @@ -331,7 +335,12 @@ public class TableFeaturesConvertorTest extends TestCase { tableFeaturesList.add(tableFeaturesBuilder.build()); } when(tableFeatures.getTableFeatures()).thenReturn(tableFeaturesList); - List tableFeatureses = TableFeaturesConvertor.toTableFeaturesRequest(tableFeatures); + Optional> tableFeaturesesOptional = + ConvertorManager.getInstance().convert(tableFeatures); + + List tableFeatureses = + tableFeaturesesOptional.orElse(Collections.emptyList()); + assertNotNull(tableFeatures); assertEquals(10, tableFeatures.getTableFeatures().size()); List tableFeaturePropertieses = tableFeatures.getTableFeatures().get(0).getTableProperties().getTableFeatureProperties(); @@ -364,4 +373,4 @@ public class TableFeaturesConvertorTest extends TestCase { tablePropertiesBuilder.setTableFeatureProperties(tableFeaturePropertieses); return tablePropertiesBuilder.build(); } -} \ No newline at end of file +} -- 2.36.6