Bug 5540 - TableFeaturesConvertor 65/40865/23
authorTomas Slusny <tomas.slusny@pantheon.sk>
Mon, 27 Jun 2016 12:24:11 +0000 (14:24 +0200)
committerTomas Slusny <tomas.slusny@pantheon.sk>
Wed, 3 Aug 2016 15:46:03 +0000 (15:46 +0000)
- Reworked TableFeaturesConvertor to use new ConvertorManager design
- Updated tests and usage of TableFeaturesConvertor accordingly

Change-Id: Ic2430412edac4cc0658f1fa7ccdecb5ebf937eef
Signed-off-by: Tomas Slusny <tomas.slusny@pantheon.sk>
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/SalTableServiceImpl.java
openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/OFRpcTaskFactory.java
openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/ConvertorManager.java
openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/TableFeaturesConvertor.java
openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/TableFeaturesConvertorTest.java

index bd38f2836a82402d362a66cac1dd7b137ecec609..86d1e7892228ac1d337708366ee9f1255c366742 100644 (file)
@@ -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<UpdateTa
     protected OfHeader buildRequest(final Xid xid, final UpdateTableInput input) {
         final MultipartRequestTableFeaturesCaseBuilder caseBuilder = new MultipartRequestTableFeaturesCaseBuilder();
         final MultipartRequestTableFeaturesBuilder requestBuilder = new MultipartRequestTableFeaturesBuilder();
-        final List<TableFeatures> ofTableFeatureList = TableFeaturesConvertor.toTableFeaturesRequest(input
-            .getUpdatedTable());
-        requestBuilder.setTableFeatures(ofTableFeatureList);
+
+        final Optional<List<TableFeatures>> ofTableFeatureList = ConvertorManager.getInstance().convert(input.getUpdatedTable());
+        requestBuilder.setTableFeatures(ofTableFeatureList.orElse(Collections.emptyList()));
         caseBuilder.setMultipartRequestTableFeatures(requestBuilder.build());
 
         // Set request body to main multipart request
index 774dce40b4463ab399f826800271df2d718a0ee7..b82abb2c42c10da4c9a8e2b68d53894999ceeeae 100644 (file)
@@ -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<TableFeatures> ofTableFeatureList = TableFeaturesConvertor
-                        .toTableFeaturesRequest(input.getUpdatedTable());
-                requestBuilder.setTableFeatures(ofTableFeatureList);
+
+                final java.util.Optional<List<TableFeatures>> ofTableFeatureList = ConvertorManager.getInstance().convert(input.getUpdatedTable());
+                requestBuilder.setTableFeatures(ofTableFeatureList.orElse(Collections.emptyList()));
                 caseBuilder.setMultipartRequestTableFeatures(requestBuilder.build());
 
                 // Set request body to main multipart request
index db46143c16ffe1e71cc8f4acfc42d963fbc61dc2..ef84bd6807057ff1af6be4131214ee4158debade 100644 (file)
@@ -32,6 +32,7 @@ public class ConvertorManager {
     static {
         INSTANCE = new ConvertorManager();
         // All convertors are registered here
+        INSTANCE.registerConvertor(new TableFeaturesConvertor());
     }
 
     // Actual convertor keys
index 111fafde91cda8ee54e4febaf808a5ebd701c3e1..d5699ed0ad59860116272c8ce03af47b2c77b6bf 100644 (file)
@@ -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:
+ * <pre>
+ * {@code
+ * Optional<List<TableFeatures>> ofFeatures = ConvertorManager.getInstance().convert(salTableFeatures);
+ * }
+ * </pre>
  */
-public class TableFeaturesConvertor {
+public class TableFeaturesConvertor implements Convertor<
+        org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.TableFeatures,
+        List<TableFeatures>> {
+
     private static final Logger LOG = LoggerFactory.getLogger(TableFeaturesConvertor.class);
     private static final Ordering<org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.features.table.features.table.properties.TableFeatureProperties> TABLE_FEATURE_PROPS_ORDERING =
             Ordering.from(OrderComparator.<org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.features.table.features.table.properties.TableFeatureProperties>build());
+    private static final Map<Class<?>, Class<? extends org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.MatchField>> SAL_TO_OF_TABLE_FEATURES;
 
-    private TableFeaturesConvertor() {
-        //hiding implicit construcotr
-    }
-
-    public static List<TableFeatures> toTableFeaturesRequest(
-            final org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.TableFeatures salTableFeaturesList) {
-        List<TableFeatures> 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<?>, Class<? extends org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.MatchField>> 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<TableFeatureProperties> toTableProperties(
             final org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.features.table.features.TableProperties tableProperties) {
         if (tableProperties == null) {
-            return Collections.<TableFeatureProperties>emptyList();
+            return Collections.emptyList();
         }
+
         List<TableFeatureProperties> ofTablePropertiesList = new ArrayList<>();
 
         List<org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.features.table.features.table.properties.TableFeatureProperties>
@@ -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<org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.set.field.match.SetFieldMatch>()
+                ((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<org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.set.field.match.SetFieldMatch>()
+                ((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<org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.set.field.match.SetFieldMatch>()
+                ((setFieldMatch == null) ? new ArrayList<>()
                         : setFieldMatch));
     }
 
@@ -289,7 +331,7 @@ public class TableFeaturesConvertor {
         setSetFieldTableFeatureProperty(
                 propBuilder,
                 TableFeaturesPropType.OFPTFPTWRITESETFIELD,
-                ((setFieldMatch == null) ? new ArrayList<org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.set.field.match.SetFieldMatch>()
+                ((setFieldMatch == null) ? new ArrayList<>()
                         : setFieldMatch));
     }
 
@@ -304,7 +346,7 @@ public class TableFeaturesConvertor {
         setSetFieldTableFeatureProperty(
                 propBuilder,
                 TableFeaturesPropType.OFPTFPTWILDCARDS,
-                ((setFieldMatch == null) ? new ArrayList<org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.set.field.match.SetFieldMatch>()
+                ((setFieldMatch == null) ? new ArrayList<>()
                         : setFieldMatch));
     }
 
@@ -319,7 +361,7 @@ public class TableFeaturesConvertor {
         setSetFieldTableFeatureProperty(
                 propBuilder,
                 TableFeaturesPropType.OFPTFPTMATCH,
-                ((setFieldMatch == null) ? new ArrayList<org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.set.field.match.SetFieldMatch>()
+                ((setFieldMatch == null) ? new ArrayList<>()
                         : setFieldMatch));
     }
 
@@ -329,7 +371,7 @@ public class TableFeaturesConvertor {
         setActionTableFeatureProperty(
                 propBuilder,
                 TableFeaturesPropType.OFPTFPTAPPLYACTIONSMISS,
-                ((applyActionsMiss == null) ? new ArrayList<org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action>()
+                ((applyActionsMiss == null) ? new ArrayList<>()
                         : applyActionsMiss.getAction()));
     }
 
@@ -338,7 +380,7 @@ public class TableFeaturesConvertor {
         setActionTableFeatureProperty(
                 propBuilder,
                 TableFeaturesPropType.OFPTFPTAPPLYACTIONS,
-                ((applyActions == null) ? new ArrayList<org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action>()
+                ((applyActions == null) ? new ArrayList<>()
                         : applyActions.getAction()));
     }
 
@@ -347,7 +389,7 @@ public class TableFeaturesConvertor {
         setActionTableFeatureProperty(
                 propBuilder,
                 TableFeaturesPropType.OFPTFPTWRITEACTIONSMISS,
-                ((writeActionsMiss == null) ? new ArrayList<org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action>()
+                ((writeActionsMiss == null) ? new ArrayList<>()
                         : writeActionsMiss.getAction()));
     }
 
@@ -356,7 +398,7 @@ public class TableFeaturesConvertor {
         setActionTableFeatureProperty(
                 propBuilder,
                 TableFeaturesPropType.OFPTFPTWRITEACTIONS,
-                ((writeActions == null) ? new ArrayList<org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action>()
+                ((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<Short>() : 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<Short>() : 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<Instruction>() : 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<Instruction>() : 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<?>, Class<? extends org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.MatchField>> SAL_TO_OF_TABLE_FEATURES;
-
-    static {
-        Builder<Class<?>, Class<? extends org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.MatchField>> 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<? extends org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.MatchField> currMatchType = currMatch
                     .getMatchType();
             MatchEntryBuilder matchEntryBuilder = new MatchEntryBuilder();
-
             Class<? extends org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.MatchField> 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<TableFeatures> convert(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.TableFeatures source) {
+        List<TableFeatures> 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;
+    }
 }
index 5e8a0f8272cbcd6cba9a76ac6fcc0d1fec62b022..fb3c14babb15c18ea54ae602f18170dae5d2b133 100644 (file)
@@ -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<org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.features.TableFeatures> tableFeaturesList = new ArrayList<>();
@@ -331,7 +335,12 @@ public class TableFeaturesConvertorTest extends TestCase {
             tableFeaturesList.add(tableFeaturesBuilder.build());
         }
         when(tableFeatures.getTableFeatures()).thenReturn(tableFeaturesList);
-        List<org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.table.features._case.multipart.request.table.features.TableFeatures> tableFeatureses = TableFeaturesConvertor.toTableFeaturesRequest(tableFeatures);
+        Optional<List<org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.table.features._case.multipart.request.table.features.TableFeatures>> tableFeaturesesOptional =
+                ConvertorManager.getInstance().convert(tableFeatures);
+
+        List<org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.table.features._case.multipart.request.table.features.TableFeatures> tableFeatureses =
+                tableFeaturesesOptional.orElse(Collections.emptyList());
+
         assertNotNull(tableFeatures);
         assertEquals(10, tableFeatures.getTableFeatures().size());
         List<TableFeatureProperties> 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
+}