X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=openflowplugin%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fopenflowplugin%2Fopenflow%2Fmd%2Fcore%2Fsal%2Fconvertor%2FTableFeaturesConvertor.java;h=38b1935b32e22079253b3eaf096bc5eceb6d2192;hb=3c34de49abdc57fe13181e370e61e06a1e0ca658;hp=22ffa9d8b1fec64c3557842eb315546fb0bc7b8e;hpb=3041a67986c066170d9a229f102aba4a01b730b4;p=openflowplugin.git 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 22ffa9d8b1..38b1935b32 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 @@ -8,8 +8,18 @@ package org.opendaylight.openflowplugin.openflow.md.core.sal.convertor; +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableMap.Builder; import com.google.common.collect.Ordering; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +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.openflowplugin.openflow.md.core.sal.convertor.data.VersionConvertorData; 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; import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.DecMplsTtlCase; @@ -33,6 +43,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instru import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.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.list.Instruction; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.approved.extensions.rev160802.TcpFlags; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev150225.ActionRelatedTableFeatureProperty; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev150225.ActionRelatedTableFeaturePropertyBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev150225.InstructionRelatedTableFeatureProperty; @@ -78,6 +89,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.ArpT import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.EthDst; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.EthSrc; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.EthType; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.ExperimenterClass; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.Icmpv4Code; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.Icmpv4Type; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.Icmpv6Code; @@ -135,52 +147,87 @@ 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.match.MatchSetfield; import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.next.table.miss.TablesMiss; import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.wildcards.WildcardSetfield; +import org.opendaylight.yang.gen.v1.urn.opendaylight.table.service.rev131026.table.update.UpdatedTable; +import org.opendaylight.yangtools.yang.binding.DataContainer; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; /** - * 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
+ * VersionConvertorData data = new VersionConvertorData(version);
+ * Optional> ofFeatures = convertorManager..convert(salTableFeatures, data);
+ * }
+ * 
*/ -public class TableFeaturesConvertor { +public class TableFeaturesConvertor extends Convertor< + org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.TableFeatures, + List, + VersionConvertorData> { + 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 static final List> TYPES = Arrays.asList(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.TableFeatures.class, UpdatedTable.class); - private TableFeaturesConvertor() { - //hiding implicit construcotr - } - - public static List toTableFeaturesRequest( - 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( - org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.features.table.features.TableProperties tableProperties) { + 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 @@ -193,7 +240,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) { @@ -223,61 +271,66 @@ 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(TableFeaturePropType propType, TableFeaturePropertiesBuilder propBuilder) { + private static void setTableFeatureProperty(final TableFeaturePropType propType) { LOG.debug("Unknown TableFeaturePropType [{}]", propType.getClass()); } - private static void setTableFeatureProperty(ApplySetfieldMiss propType, TableFeaturePropertiesBuilder propBuilder) { + private static void setTableFeatureProperty(final ApplySetfieldMiss propType, final TableFeaturePropertiesBuilder propBuilder) { List setFieldMatch = null; - org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.apply.setfield.miss.ApplySetfieldMiss applySetfieldMiss = ((ApplySetfieldMiss) propType).getApplySetfieldMiss(); + org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.apply.setfield.miss.ApplySetfieldMiss applySetfieldMiss = propType.getApplySetfieldMiss(); if (null != applySetfieldMiss) { setFieldMatch = applySetfieldMiss.getSetFieldMatch(); } + setSetFieldTableFeatureProperty( propBuilder, TableFeaturesPropType.OFPTFPTAPPLYSETFIELDMISS, - ((setFieldMatch == null) ? new ArrayList() + ((setFieldMatch == null) ? new ArrayList<>() : setFieldMatch)); } - private static void setTableFeatureProperty(ApplySetfield propType, TableFeaturePropertiesBuilder propBuilder) { + private static void setTableFeatureProperty(final ApplySetfield propType, final TableFeaturePropertiesBuilder propBuilder) { List setFieldMatch = null; - org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.apply.setfield.ApplySetfield applySetfield = ((ApplySetfield) propType).getApplySetfield(); + org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.apply.setfield.ApplySetfield applySetfield = propType.getApplySetfield(); if (null != applySetfield) { setFieldMatch = applySetfield.getSetFieldMatch(); } + setSetFieldTableFeatureProperty( propBuilder, TableFeaturesPropType.OFPTFPTAPPLYSETFIELD, - ((setFieldMatch == null) ? new ArrayList() + ((setFieldMatch == null) ? new ArrayList<>() : setFieldMatch)); } - private static void setTableFeatureProperty(WriteSetfieldMiss propType, TableFeaturePropertiesBuilder propBuilder) { + private static void setTableFeatureProperty(final WriteSetfieldMiss propType, final TableFeaturePropertiesBuilder propBuilder) { List setFieldMatch = null; - org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.write.setfield.miss.WriteSetfieldMiss writeSetfieldMiss = ((WriteSetfieldMiss) propType).getWriteSetfieldMiss(); + org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.write.setfield.miss.WriteSetfieldMiss writeSetfieldMiss = propType.getWriteSetfieldMiss(); if (null != writeSetfieldMiss) { setFieldMatch = writeSetfieldMiss.getSetFieldMatch(); } + setSetFieldTableFeatureProperty( propBuilder, TableFeaturesPropType.OFPTFPTWRITESETFIELDMISS, - ((setFieldMatch == null) ? new ArrayList() + ((setFieldMatch == null) ? new ArrayList<>() : setFieldMatch)); } - private static void setTableFeatureProperty(WriteSetfield propType, TableFeaturePropertiesBuilder propBuilder) { + private static void setTableFeatureProperty(final WriteSetfield propType, final TableFeaturePropertiesBuilder propBuilder) { List setFieldMatch = null; - org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.write.setfield.WriteSetfield writeSetField = ((WriteSetfield) propType).getWriteSetfield(); + org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.write.setfield.WriteSetfield writeSetField = propType.getWriteSetfield(); if (null != writeSetField) { setFieldMatch = writeSetField.getSetFieldMatch(); @@ -286,13 +339,13 @@ public class TableFeaturesConvertor { setSetFieldTableFeatureProperty( propBuilder, TableFeaturesPropType.OFPTFPTWRITESETFIELD, - ((setFieldMatch == null) ? new ArrayList() + ((setFieldMatch == null) ? new ArrayList<>() : setFieldMatch)); } - private static void setTableFeatureProperty(Wildcards propType, TableFeaturePropertiesBuilder propBuilder) { + private static void setTableFeatureProperty(final Wildcards propType, final TableFeaturePropertiesBuilder propBuilder) { List setFieldMatch = null; - WildcardSetfield wildcardSetField = ((Wildcards) propType).getWildcardSetfield(); + WildcardSetfield wildcardSetField = propType.getWildcardSetfield(); if (null != wildcardSetField) { setFieldMatch = wildcardSetField.getSetFieldMatch(); @@ -301,12 +354,12 @@ public class TableFeaturesConvertor { setSetFieldTableFeatureProperty( propBuilder, TableFeaturesPropType.OFPTFPTWILDCARDS, - ((setFieldMatch == null) ? new ArrayList() + ((setFieldMatch == null) ? new ArrayList<>() : setFieldMatch)); } - private static void setTableFeatureProperty(Match propType, TableFeaturePropertiesBuilder propBuilder) { - MatchSetfield matchSetField = ((Match) propType).getMatchSetfield(); + private static void setTableFeatureProperty(final Match propType, final TableFeaturePropertiesBuilder propBuilder) { + MatchSetfield matchSetField = propType.getMatchSetfield(); List setFieldMatch = null; if (null != matchSetField) { @@ -316,80 +369,77 @@ public class TableFeaturesConvertor { setSetFieldTableFeatureProperty( propBuilder, TableFeaturesPropType.OFPTFPTMATCH, - ((setFieldMatch == null) ? new ArrayList() + ((setFieldMatch == null) ? new ArrayList<>() : setFieldMatch)); } - private static void setTableFeatureProperty(ApplyActionsMiss propType, TableFeaturePropertiesBuilder propBuilder) { - org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.apply.actions.miss.ApplyActionsMiss applyActionsMiss = ((ApplyActionsMiss) propType) + private static void setTableFeatureProperty(final ApplyActionsMiss propType, final TableFeaturePropertiesBuilder propBuilder) { + org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.apply.actions.miss.ApplyActionsMiss applyActionsMiss = propType .getApplyActionsMiss(); setActionTableFeatureProperty( propBuilder, TableFeaturesPropType.OFPTFPTAPPLYACTIONSMISS, - ((applyActionsMiss == null) ? new ArrayList() + ((applyActionsMiss == null) ? new ArrayList<>() : applyActionsMiss.getAction())); } - private static void setTableFeatureProperty(ApplyActions propType, TableFeaturePropertiesBuilder propBuilder) { - org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.apply.actions.ApplyActions applyActions = ((ApplyActions) propType) - .getApplyActions(); + private static void setTableFeatureProperty(final ApplyActions propType, final TableFeaturePropertiesBuilder propBuilder) { + org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.apply.actions.ApplyActions applyActions = propType.getApplyActions(); setActionTableFeatureProperty( propBuilder, TableFeaturesPropType.OFPTFPTAPPLYACTIONS, - ((applyActions == null) ? new ArrayList() + ((applyActions == null) ? new ArrayList<>() : applyActions.getAction())); } - private static void setTableFeatureProperty(WriteActionsMiss propType, TableFeaturePropertiesBuilder propBuilder) { - org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.write.actions.miss.WriteActionsMiss writeActionsMiss = ((WriteActionsMiss) propType) - .getWriteActionsMiss(); + private static void setTableFeatureProperty(final WriteActionsMiss propType, final TableFeaturePropertiesBuilder propBuilder) { + org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.write.actions.miss.WriteActionsMiss writeActionsMiss = propType.getWriteActionsMiss(); setActionTableFeatureProperty( propBuilder, TableFeaturesPropType.OFPTFPTWRITEACTIONSMISS, - ((writeActionsMiss == null) ? new ArrayList() + ((writeActionsMiss == null) ? new ArrayList<>() : writeActionsMiss.getAction())); } - private static void setTableFeatureProperty(WriteActions propType, TableFeaturePropertiesBuilder propBuilder) { - org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.write.actions.WriteActions writeActions = ((WriteActions) propType) - .getWriteActions(); + private static void setTableFeatureProperty(final WriteActions propType, final TableFeaturePropertiesBuilder propBuilder) { + org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.write.actions.WriteActions writeActions = propType.getWriteActions(); setActionTableFeatureProperty( propBuilder, TableFeaturesPropType.OFPTFPTWRITEACTIONS, - ((writeActions == null) ? new ArrayList() + ((writeActions == null) ? new ArrayList<>() : writeActions.getAction())); } - private static void setTableFeatureProperty(NextTableMiss propType, TableFeaturePropertiesBuilder propBuilder) { - TablesMiss tables = ((NextTableMiss) propType) + private static void setTableFeatureProperty(final NextTableMiss propType, final TableFeaturePropertiesBuilder propBuilder) { + TablesMiss tables = propType .getTablesMiss(); setNextTableFeatureProperty(propBuilder, TableFeaturesPropType.OFPTFPTNEXTTABLESMISS, - (tables == null) ? new ArrayList() : tables.getTableIds()); + (tables == null) ? new ArrayList<>() : tables.getTableIds()); } - private static void setTableFeatureProperty(NextTable propType, TableFeaturePropertiesBuilder propBuilder) { - org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.next.table.Tables tables = ((NextTable) propType) + 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(InstructionsMiss propType, TableFeaturePropertiesBuilder propBuilder) { - org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.instructions.miss.InstructionsMiss instructions = ((InstructionsMiss) propType) + 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(Instructions propType, TableFeaturePropertiesBuilder propBuilder) { - org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.instructions.Instructions instructions = ((Instructions) propType) + 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(TableFeaturePropertiesBuilder builder, - TableFeaturesPropType type, List instructionList) { + private static void setInstructionTableFeatureProperty(final TableFeaturePropertiesBuilder builder, + final TableFeaturesPropType type, final List instructionList) { List instructionTypeList = new ArrayList<>(); for (Instruction currInstruction : instructionList) { @@ -397,6 +447,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,17 +467,19 @@ 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); builder.addAugmentation(InstructionRelatedTableFeatureProperty.class, propBuilder.build()); } - private static void setNextTableFeatureProperty(TableFeaturePropertiesBuilder builder, TableFeaturesPropType type, - List tableIds) { + private static void setNextTableFeatureProperty(final TableFeaturePropertiesBuilder builder, final TableFeaturesPropType type, + final List tableIds) { List nextTableIdsList = new ArrayList<>(); for (Short tableId : tableIds) { @@ -434,15 +487,16 @@ public class TableFeaturesConvertor { nextTableId.setTableId(tableId); nextTableIdsList.add(nextTableId.build()); } + NextTableRelatedTableFeaturePropertyBuilder propBuilder = new NextTableRelatedTableFeaturePropertyBuilder(); propBuilder.setNextTableIds(nextTableIdsList); builder.setType(type); builder.addAugmentation(NextTableRelatedTableFeatureProperty.class, propBuilder.build()); } - private static void setActionTableFeatureProperty(TableFeaturePropertiesBuilder builder, - TableFeaturesPropType type, - List salActions) { + private static void setActionTableFeatureProperty(final TableFeaturePropertiesBuilder builder, + final TableFeaturesPropType type, + final List salActions) { List actionList = new ArrayList<>(); @@ -450,6 +504,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 +554,7 @@ public class TableFeaturesConvertor { PopPbbCaseBuilder popPbbCaseBuilder = new PopPbbCaseBuilder(); actionBuilder.setActionChoice(popPbbCaseBuilder.build()); } + // Experimenter action is unhandled actionList.add(actionBuilder.build()); } @@ -509,81 +565,66 @@ public class TableFeaturesConvertor { builder.addAugmentation(ActionRelatedTableFeatureProperty.class, propBuilder.build()); } - private static Map, Class> SAL_TO_OF_TABLE_FEATURES = new HashMap<>(); - - static { - SAL_TO_OF_TABLE_FEATURES.put(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.ArpOp.class, ArpOp.class); - SAL_TO_OF_TABLE_FEATURES.put(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.ArpSha.class, ArpSha.class); - SAL_TO_OF_TABLE_FEATURES.put(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.ArpSpa.class, ArpSpa.class); - SAL_TO_OF_TABLE_FEATURES.put(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.ArpTha.class, ArpTha.class); - SAL_TO_OF_TABLE_FEATURES.put(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.ArpTpa.class, ArpTpa.class); - SAL_TO_OF_TABLE_FEATURES.put(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.EthDst.class, EthDst.class); - SAL_TO_OF_TABLE_FEATURES.put(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.EthSrc.class, EthSrc.class); - SAL_TO_OF_TABLE_FEATURES.put(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.EthType.class, EthType.class); - SAL_TO_OF_TABLE_FEATURES.put(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.Icmpv4Code.class, Icmpv4Code.class); - SAL_TO_OF_TABLE_FEATURES.put(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.Icmpv4Type.class, Icmpv4Type.class); - SAL_TO_OF_TABLE_FEATURES.put(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.Icmpv6Code.class, Icmpv6Code.class); - SAL_TO_OF_TABLE_FEATURES.put(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.Icmpv6Type.class, Icmpv6Type.class); - SAL_TO_OF_TABLE_FEATURES.put(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.InPhyPort.class, InPhyPort.class); - SAL_TO_OF_TABLE_FEATURES.put(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.InPort.class, InPort.class); - SAL_TO_OF_TABLE_FEATURES.put(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.IpDscp.class, IpDscp.class); - SAL_TO_OF_TABLE_FEATURES.put(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.IpEcn.class, IpEcn.class); - SAL_TO_OF_TABLE_FEATURES.put(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.IpProto.class, IpProto.class); - SAL_TO_OF_TABLE_FEATURES.put(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.Ipv4Dst.class, Ipv4Dst.class); - SAL_TO_OF_TABLE_FEATURES.put(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.Ipv4Src.class, Ipv4Src.class); - SAL_TO_OF_TABLE_FEATURES.put(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.Ipv6Dst.class, Ipv6Dst.class); - SAL_TO_OF_TABLE_FEATURES.put(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.Ipv6Exthdr.class, Ipv6Exthdr.class); - SAL_TO_OF_TABLE_FEATURES.put(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.Ipv6Flabel.class, Ipv6Flabel.class); - SAL_TO_OF_TABLE_FEATURES.put(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.Ipv6NdSll.class, Ipv6NdSll.class); - SAL_TO_OF_TABLE_FEATURES.put(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.Ipv6NdTarget.class, Ipv6NdTarget.class); - SAL_TO_OF_TABLE_FEATURES.put(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.Ipv6NdTll.class, Ipv6NdTll.class); - SAL_TO_OF_TABLE_FEATURES.put(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.Ipv6Src.class, Ipv6Src.class); - SAL_TO_OF_TABLE_FEATURES.put(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.Metadata.class, Metadata.class); - SAL_TO_OF_TABLE_FEATURES.put(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.MplsBos.class, MplsBos.class); - SAL_TO_OF_TABLE_FEATURES.put(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.MplsLabel.class, MplsLabel.class); - SAL_TO_OF_TABLE_FEATURES.put(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.MplsTc.class, MplsTc.class); - SAL_TO_OF_TABLE_FEATURES.put(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.PbbIsid.class, PbbIsid.class); - SAL_TO_OF_TABLE_FEATURES.put(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.SctpDst.class, SctpDst.class); - SAL_TO_OF_TABLE_FEATURES.put(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.SctpSrc.class, SctpSrc.class); - SAL_TO_OF_TABLE_FEATURES.put(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.TcpDst.class, TcpDst.class); - SAL_TO_OF_TABLE_FEATURES.put(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.TcpSrc.class, TcpSrc.class); - SAL_TO_OF_TABLE_FEATURES.put(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.TunnelId.class, TunnelId.class); - SAL_TO_OF_TABLE_FEATURES.put(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.UdpDst.class, UdpDst.class); - SAL_TO_OF_TABLE_FEATURES.put(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.UdpSrc.class, UdpSrc.class); - SAL_TO_OF_TABLE_FEATURES.put(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.VlanPcp.class, VlanPcp.class); - SAL_TO_OF_TABLE_FEATURES.put(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.VlanVid.class, VlanVid.class); - SAL_TO_OF_TABLE_FEATURES.put(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.TunnelIpv4Dst.class, Ipv4Dst.class); - SAL_TO_OF_TABLE_FEATURES.put(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.TunnelIpv4Src.class, Ipv4Src.class); - } - private static void setSetFieldTableFeatureProperty( - TableFeaturePropertiesBuilder builder, - TableFeaturesPropType type, - List setFields) { + final TableFeaturePropertiesBuilder builder, + final TableFeaturesPropType type, + final List setFields) { List matchEntriesList = new ArrayList<>(); for (org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.set.field.match.SetFieldMatch currMatch : setFields) { 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); builder.addAugmentation(OxmRelatedTableFeatureProperty.class, propBuilder.build()); } - private static void setMatchEntry(MatchEntryBuilder builder, - Class field, - Boolean hasMask) { - builder.setOxmClass(OpenflowBasicClass.class); + private static void setMatchEntry(final MatchEntryBuilder builder, + final Class field, + final Boolean hasMask) { + if(field == TcpFlags.class) { + builder.setOxmClass(ExperimenterClass.class); + } else { + builder.setOxmClass(OpenflowBasicClass.class); + } builder.setOxmMatchField(field); builder.setHasMask(hasMask); } + + @Override + public Collection> getTypes() { + return TYPES; + } + + @Override + public List convert(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.TableFeatures source, VersionConvertorData data) { + 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; + } }