Cleanup ofp nicira extension 89/94389/16
authorRobert Varga <robert.varga@pantheon.tech>
Mon, 4 Jan 2021 00:40:14 +0000 (01:40 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Tue, 5 Jan 2021 09:55:28 +0000 (10:55 +0100)
Fix warnings coming from uint type widening and clean up builder
usage.

Also optimize MatchUtil.ipv4ToLong() by using IetfInetUtil, since
which is the most efficient way of during that conversion. This
leads to a cleanup of MatchUtil, which is taught to operate on Uint32
instead.

Change-Id: I6219f47d4dc06b046b1fce5c7acd699edd96d3ad
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
12 files changed:
extension/openflowplugin-extension-nicira/src/main/java/org/opendaylight/openflowplugin/extension/vendor/nicira/convertor/action/FieldChoiceResolver.java
extension/openflowplugin-extension-nicira/src/main/java/org/opendaylight/openflowplugin/extension/vendor/nicira/convertor/action/MultipathConvertor.java
extension/openflowplugin-extension-nicira/src/main/java/org/opendaylight/openflowplugin/extension/vendor/nicira/convertor/action/OutputRegConvertor.java
extension/openflowplugin-extension-nicira/src/main/java/org/opendaylight/openflowplugin/extension/vendor/nicira/convertor/action/RegLoad2Convertor.java
extension/openflowplugin-extension-nicira/src/main/java/org/opendaylight/openflowplugin/extension/vendor/nicira/convertor/action/RegLoadConvertor.java
extension/openflowplugin-extension-nicira/src/main/java/org/opendaylight/openflowplugin/extension/vendor/nicira/convertor/action/RegMoveConvertor.java
extension/openflowplugin-extension-nicira/src/main/java/org/opendaylight/openflowplugin/extension/vendor/nicira/convertor/match/ArpSpaConvertor.java
extension/openflowplugin-extension-nicira/src/main/java/org/opendaylight/openflowplugin/extension/vendor/nicira/convertor/match/ArpTpaConvertor.java
extension/openflowplugin-extension-nicira/src/main/java/org/opendaylight/openflowplugin/extension/vendor/nicira/convertor/match/MatchUtil.java
extension/openflowplugin-extension-nicira/src/main/java/org/opendaylight/openflowplugin/extension/vendor/nicira/convertor/match/TunIPv4DstConvertor.java
extension/openflowplugin-extension-nicira/src/main/java/org/opendaylight/openflowplugin/extension/vendor/nicira/convertor/match/TunIPv4SrcConvertor.java
extension/openflowplugin-extension-nicira/src/test/java/org/opendaylight/openflowplugin/extension/vendor/nicira/convertor/MatchUtilTest.java

index 210cca48d206a0210e38e4d7d038f2349dc14da0..3d79e9f23c1902fde01d181cf8cbb455bb73facb 100644 (file)
@@ -291,11 +291,11 @@ public final class FieldChoiceResolver {
      * @param header the OXM/NXM header.
      * @return the destination choice.
      */
-    static DstChoice resolveDstChoice(Uint32 header) {
+    static DstChoice resolveDstChoice(final Uint32 header) {
         return NXMHEADER_TO_DST_CHOICE.get(header.toJava());
     }
 
-    static DstChoice resolveDstChoice(Long header) {
+    static DstChoice resolveDstChoice(final Long header) {
         return NXMHEADER_TO_DST_CHOICE.get(header);
     }
 
@@ -306,7 +306,7 @@ public final class FieldChoiceResolver {
      * @param header the OXM/NXM header.
      * @return the destination choice.
      */
-    static DstChoice resolveDstChoice(Uint64 header) {
+    static DstChoice resolveDstChoice(final Uint64 header) {
         return NXMHEADER_TO_DST_CHOICE.get(header);
     }
 
@@ -317,11 +317,11 @@ public final class FieldChoiceResolver {
      * @param header the OXM/NXM header.
      * @return the source choice.
      */
-    static SrcChoice resolveSrcChoice(Long header) {
+    static SrcChoice resolveSrcChoice(final Long header) {
         return NXMHEADER_TO_SRC_CHOICE.get(header);
     }
 
-    static SrcChoice resolveSrcChoice(Uint32 header) {
+    static SrcChoice resolveSrcChoice(final Uint32 header) {
         return NXMHEADER_TO_SRC_CHOICE.get(header.toJava());
     }
 
@@ -332,7 +332,7 @@ public final class FieldChoiceResolver {
      * @param header the OXM/NXM header.
      * @return the destination choice.
      */
-    static SrcChoice resolveSrcChoice(Uint64 header) {
+    static SrcChoice resolveSrcChoice(final Uint64 header) {
         return NXMHEADER_TO_SRC_CHOICE.get(header);
     }
 
@@ -344,14 +344,14 @@ public final class FieldChoiceResolver {
      * @return the OXM/NXM header as uint32 {@code Long}.
      * @throws IllegalArgumentException if the field is experimenter.
      */
-    static Long resolveDstHeaderUint32(DstChoice dstChoice) {
+    static Uint32 resolveDstHeaderUint32(final DstChoice dstChoice) {
         NxmHeader nxmHeader = dstChoice instanceof DstNxRegCase
                 ? REG_DST_CHOICE_TO_NXMHEADER.get(dstChoice)
                 : DST_CHOICE_TYPE_TO_NXMHEADER.get(dstChoice.implementedInterface());
         if (nxmHeader.isExperimenter()) {
             throw new IllegalArgumentException("Cannot fit experimenter destination choice on a uint32 header");
         }
-        return nxmHeader.toLong();
+        return Uint32.valueOf(nxmHeader.toLong());
     }
 
     /**
@@ -361,7 +361,7 @@ public final class FieldChoiceResolver {
      * @param dstChoice the destination choice field.
      * @return the OXM/NXM header as uint64 {@code BigInteger}.
      */
-    static Uint64 resolveDstHeaderUint64(DstChoice dstChoice) {
+    static Uint64 resolveDstHeaderUint64(final DstChoice dstChoice) {
         return dstChoice instanceof DstNxRegCase
                 ? REG_DST_CHOICE_TO_NXMHEADER.get(dstChoice).toUint64()
                 : DST_CHOICE_TYPE_TO_NXMHEADER.get(dstChoice.implementedInterface()).toUint64();
@@ -375,14 +375,14 @@ public final class FieldChoiceResolver {
      * @return the OXM/NXM header as uint32 {@code Long}.
      * @throws IllegalArgumentException if the field is experimenter.
      */
-    static Long resolveSrcHeaderUint32(SrcChoice srcChoice) {
+    static Uint32 resolveSrcHeaderUint32(final SrcChoice srcChoice) {
         NxmHeader nxmHeader = srcChoice instanceof SrcNxRegCase
                 ? REG_SRC_CHOICE_TO_NXMHEADER.get(srcChoice)
                 : SRC_CHOICE_TYPE_TO_NXMHEADER.get(srcChoice.implementedInterface());
         if (nxmHeader.isExperimenter()) {
             throw new IllegalArgumentException("Cannot fit experimenter source choice on a uint32 header");
         }
-        return nxmHeader.toLong();
+        return Uint32.valueOf(nxmHeader.toLong());
     }
 
     /**
@@ -392,7 +392,7 @@ public final class FieldChoiceResolver {
      * @param srcChoice the destination choice field.
      * @return the OXM/NXM header as uint64 {@code BigInteger}.
      */
-    static Uint64 resolveSrcHeaderUint64(SrcChoice srcChoice) {
+    static Uint64 resolveSrcHeaderUint64(final SrcChoice srcChoice) {
         return srcChoice instanceof SrcNxRegCase
                 ? REG_SRC_CHOICE_TO_NXMHEADER.get(srcChoice).toUint64()
                 : SRC_CHOICE_TYPE_TO_NXMHEADER.get(srcChoice.implementedInterface()).toUint64();
@@ -404,7 +404,7 @@ public final class FieldChoiceResolver {
      * @param srcChoice the source choice field.
      * @return true if experimenter.
      */
-    static boolean isExperimenter(SrcChoice srcChoice) {
+    static boolean isExperimenter(final SrcChoice srcChoice) {
         return srcChoice instanceof SrcNxRegCase
                 ? REG_SRC_CHOICE_TO_NXMHEADER.get(srcChoice).isExperimenter()
                 : SRC_CHOICE_TYPE_TO_NXMHEADER.get(srcChoice.implementedInterface()).isExperimenter();
@@ -416,7 +416,7 @@ public final class FieldChoiceResolver {
      * @param dstChoice the destination choice field.
      * @return true if experimenter.
      */
-    static boolean isExperimenter(DstChoice dstChoice) {
+    static boolean isExperimenter(final DstChoice dstChoice) {
         return dstChoice instanceof DstNxRegCase
                 ? REG_DST_CHOICE_TO_NXMHEADER.get(dstChoice).isExperimenter()
                 : DST_CHOICE_TYPE_TO_NXMHEADER.get(dstChoice.implementedInterface()).isExperimenter();
index 6fe6ae277811007bce51935e27fa71f23198bfb7..4875718723da76aba37e198984e24f7fd46cc450 100644 (file)
@@ -51,7 +51,7 @@ public class MultipathConvertor implements
         Dst dst = nxAction.getNxMultipath().getDst();
 
         final int start = dst.getStart().toJava();
-        nxActionMultipathBuilder.setOfsNbits(start << 6 | dst.getEnd().toJava() - start);
+        nxActionMultipathBuilder.setOfsNbits(Uint16.valueOf(start << 6 | dst.getEnd().toJava() - start));
         // We resolve the destination as a uint32 header, multipath action
         // does not support 8-byte experimenter headers.
         nxActionMultipathBuilder.setDst(FieldChoiceResolver.resolveDstHeaderUint32(dst.getDstChoice()));
index 436be45a1729fbc08d58365be55e04ae74b1f476..b806b2d9aaa641bfdd9f1e9835ce838f78c88f15 100644 (file)
@@ -7,7 +7,8 @@
  */
 package org.opendaylight.openflowplugin.extension.vendor.nicira.convertor.action;
 
-import com.google.common.base.Preconditions;
+import static com.google.common.base.Preconditions.checkArgument;
+
 import org.opendaylight.openflowplugin.extension.api.ConvertorActionFromOFJava;
 import org.opendaylight.openflowplugin.extension.api.ConvertorActionToOFJava;
 import org.opendaylight.openflowplugin.extension.api.path.ActionPath;
@@ -15,7 +16,6 @@ import org.opendaylight.openflowplugin.extension.vendor.nicira.convertor.CodecPr
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.Action;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.action.rev140421.action.container.action.choice.ActionOutputReg;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.action.rev140421.action.container.action.choice.ActionOutputRegBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.action.rev140421.ofj.nx.action.output.reg.grouping.NxActionOutputReg;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.action.rev140421.ofj.nx.action.output.reg.grouping.NxActionOutputRegBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.NxActionOutputRegGrouping;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.flows.statistics.update.flow.and.statistics.map.list.instructions.instruction.instruction.apply.actions._case.apply.actions.action.action.NxActionOutputRegNotifFlowsStatisticsUpdateApplyActionsCaseBuilder;
@@ -27,7 +27,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.ni
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.nodes.node.table.flow.instructions.instruction.instruction.write.actions._case.write.actions.action.action.NxActionOutputRegNodesNodeTableFlowWriteActionsCaseBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.nx.action.output.reg.grouping.NxOutputReg;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.nx.action.output.reg.grouping.NxOutputRegBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.nx.action.output.reg.grouping.nx.output.reg.Src;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.nx.action.output.reg.grouping.nx.output.reg.SrcBuilder;
 
 /**
@@ -42,29 +41,29 @@ public class OutputRegConvertor implements
     @Override
     public org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action convert(
             final Action input, final ActionPath path) {
-        NxActionOutputReg action = ((ActionOutputReg) input.getActionChoice()).getNxActionOutputReg();
-        SrcBuilder srcBuilder = new SrcBuilder();
-        srcBuilder.setSrcChoice(FieldChoiceResolver.resolveSrcChoice(action.getSrc()));
-        srcBuilder.setOfsNbits(action.getNBits());
-        NxOutputRegBuilder builder = new NxOutputRegBuilder();
-        builder.setSrc(srcBuilder.build());
-        builder.setMaxLen(action.getMaxLen());
-        return resolveAction(builder.build(), path);
+        final var action = ((ActionOutputReg) input.getActionChoice()).getNxActionOutputReg();
+        return resolveAction(new NxOutputRegBuilder()
+            .setSrc(new SrcBuilder()
+                .setSrcChoice(FieldChoiceResolver.resolveSrcChoice(action.getSrc()))
+                .setOfsNbits(action.getNBits())
+                .build())
+            .setMaxLen(action.getMaxLen())
+            .build(), path);
     }
 
     @Override
     public Action convert(
             final org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action nxActionArg) {
-        Preconditions.checkArgument(nxActionArg instanceof NxActionOutputRegGrouping);
-        NxActionOutputRegGrouping nxAction = (NxActionOutputRegGrouping) nxActionArg;
-        Src src = nxAction.getNxOutputReg().getSrc();
-        final ActionOutputRegBuilder builder = new ActionOutputRegBuilder();
-        NxActionOutputRegBuilder nxActionOutputRegBuilder = new NxActionOutputRegBuilder();
-        nxActionOutputRegBuilder.setSrc(FieldChoiceResolver.resolveSrcHeaderUint32(src.getSrcChoice()));
-        nxActionOutputRegBuilder.setNBits(src.getOfsNbits());
-        nxActionOutputRegBuilder.setMaxLen(nxAction.getNxOutputReg().getMaxLen());
-        builder.setNxActionOutputReg(nxActionOutputRegBuilder.build());
-        return ActionUtil.createAction(builder.build());
+        checkArgument(nxActionArg instanceof NxActionOutputRegGrouping);
+        final var nxAction = (NxActionOutputRegGrouping) nxActionArg;
+        final var src = nxAction.getNxOutputReg().getSrc();
+        return ActionUtil.createAction(new ActionOutputRegBuilder()
+            .setNxActionOutputReg(new NxActionOutputRegBuilder()
+                .setSrc(FieldChoiceResolver.resolveSrcHeaderUint32(src.getSrcChoice()))
+                .setNBits(src.getOfsNbits())
+                .setMaxLen(nxAction.getNxOutputReg().getMaxLen())
+                .build())
+            .build());
     }
 
     static org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action resolveAction(
index ab9997f6cae549e332b847367d290584648cb1c3..a48ab21a1a2cb51fc70a7f41b2ba2569165b24f4 100644 (file)
@@ -90,8 +90,8 @@ public class RegLoad2Convertor implements
         ConvertorActionFromOFJava<Action, ActionPath> {
 
     @Override
-    public org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action convert(Action input,
-                                                                                                      ActionPath path) {
+    public org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action convert(
+            final Action input, final ActionPath path) {
         NxActionRegLoad2 actionRegLoad2 = ((ActionRegLoad2) input.getActionChoice()).getNxActionRegLoad2();
         MatchEntry matchEntry = actionRegLoad2.getMatchEntry().get(0);
         NxRegLoad nxRegLoad = resolveRegLoad(matchEntry);
@@ -100,7 +100,7 @@ public class RegLoad2Convertor implements
 
     @Override
     public Action convert(
-            org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action actionCase) {
+            final org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action actionCase) {
         Preconditions.checkArgument(actionCase instanceof NxActionRegLoadGrouping);
 
         NxActionRegLoadGrouping nxAction = (NxActionRegLoadGrouping) actionCase;
@@ -112,7 +112,7 @@ public class RegLoad2Convertor implements
         return ActionUtil.createAction(actionRegLoad2);
     }
 
-    private static MatchEntry resolveMatchEntry(NxRegLoad nxRegLoad) {
+    private static MatchEntry resolveMatchEntry(final NxRegLoad nxRegLoad) {
         Dst dst = nxRegLoad.getDst();
         Uint64 value = nxRegLoad.getValue();
         Uint16 start = dst.getStart();
@@ -124,7 +124,7 @@ public class RegLoad2Convertor implements
         return resolveMatchEntry(dstChoice, value, mask);
     }
 
-    private static MatchEntry resolveMatchEntry(DstChoice dstChoice, Uint64 value, Uint64 mask) {
+    private static MatchEntry resolveMatchEntry(final DstChoice dstChoice, final Uint64 value, final Uint64 mask) {
         try {
             if (dstChoice instanceof DstNxNshFlagsCase) {
                 return NshFlagsConvertor.buildMatchEntry(Uint8.valueOf(value), Uint8.valueOf(mask));
@@ -157,7 +157,7 @@ public class RegLoad2Convertor implements
         throw new CodecPreconditionException("Missing implementation of a case in dst-choice? " + dstChoice.getClass());
     }
 
-    private static NxRegLoad resolveRegLoad(MatchEntry matchEntry) {
+    private static NxRegLoad resolveRegLoad(final MatchEntry matchEntry) {
         Class<? extends MatchField> oxmMatchField = matchEntry.getOxmMatchField();
         ExperimenterIdCase experimenterIdCase = (ExperimenterIdCase) matchEntry.getMatchEntryValue();
         OfjAugNxExpMatch ofjAugNxExpMatch = experimenterIdCase.augmentation(OfjAugNxExpMatch.class);
@@ -167,9 +167,9 @@ public class RegLoad2Convertor implements
     }
 
     private static NxRegLoad resolveRegLoad(
-            Class<? extends MatchField> oxmMatchField,
-            NxExpMatchEntryValue value,
-            DstBuilder dstBuilder) {
+            final Class<? extends MatchField> oxmMatchField,
+            final NxExpMatchEntryValue value,
+            final DstBuilder dstBuilder) {
 
         if (NxmNxNshFlags.class.equals(oxmMatchField)) {
             int valueLength = NiciraMatchCodecs.NSH_FLAGS_CODEC.getValueLength();
@@ -223,29 +223,20 @@ public class RegLoad2Convertor implements
         throw new CodecPreconditionException("Missing codec for " + value.implementedInterface());
     }
 
-    private static NxRegLoad resolveRegLoad(Uint8 value, @Nullable Uint8 mask, int valueLength, DstBuilder dstBuilder) {
-        return resolveRegLoad(
-                Uint64.valueOf(value),
-                mask == null ? null : Uint64.valueOf(mask),
-                valueLength,
-                dstBuilder);
+    private static NxRegLoad resolveRegLoad(final Uint8 value, final @Nullable Uint8 mask, final int valueLength,
+            final DstBuilder dstBuilder) {
+        return resolveRegLoad(value.toUint64(), mask == null ? null : mask.toUint64(), valueLength, dstBuilder);
     }
 
-    private static NxRegLoad resolveRegLoad(Uint32 value, @Nullable Uint32 mask, int valueLength,
-            DstBuilder dstBuilder) {
-        return resolveRegLoad(
-            Uint64.valueOf(value),
-                mask == null ? null : Uint64.valueOf(mask),
-                valueLength,
-                dstBuilder);
+    private static NxRegLoad resolveRegLoad(final Uint32 value, final @Nullable Uint32 mask, final int valueLength,
+            final DstBuilder dstBuilder) {
+        return resolveRegLoad(value.toUint64(), mask == null ? null : mask.toUint64(), valueLength, dstBuilder);
     }
 
     // Convert the value/mask pair of the openflowjava reg_load2 action to the
     // value/bit range pair of the openfloplugin reg_load action.
-    private static NxRegLoad resolveRegLoad(Uint64 value,
-                                            @Nullable Uint64 mask,
-                                            int length,
-                                            DstBuilder dstBuilder) {
+    private static NxRegLoad resolveRegLoad(Uint64 value, final @Nullable Uint64 mask, final int length,
+            final DstBuilder dstBuilder) {
         final int start;
         final int end;
         if (mask == null) {
@@ -268,12 +259,10 @@ public class RegLoad2Convertor implements
             value = Uint64.fromLongBits(newValueBits);
         }
 
-        dstBuilder.setStart(start);
-        dstBuilder.setEnd(end - 1);
-        NxRegLoadBuilder nxRegLoadBuilder = new NxRegLoadBuilder();
-        nxRegLoadBuilder.setDst(dstBuilder.build());
-        nxRegLoadBuilder.setValue(value);
-        return nxRegLoadBuilder.build();
+        return new NxRegLoadBuilder()
+            .setDst(dstBuilder.setStart(Uint16.valueOf(start)).setEnd(Uint16.valueOf(end - 1)).build())
+            .setValue(value)
+            .build();
     }
 
     private static int lowestSetBit(final long value) {
@@ -286,7 +275,7 @@ public class RegLoad2Convertor implements
 
     // Convert value/bit range pair of the openfloplugin reg_load action to the
     // value/mask pair of the openflowjava reg_load2 action.
-    private static Uint64[] resolveValueMask(Uint64 value, Uint16 start, Uint16 end) {
+    private static Uint64[] resolveValueMask(final Uint64 value, final Uint16 start, final Uint16 end) {
         final int startInt = start.toJava();
         final int bits = end.toJava() - startInt + 1;
         final long valueBits = value.longValue();
index 571391908251654e61562650ac2dd43fcefb1c22..c451dad6238b6b7cc943a77f5341b0162a6a3976 100644 (file)
@@ -7,7 +7,8 @@
  */
 package org.opendaylight.openflowplugin.extension.vendor.nicira.convertor.action;
 
-import com.google.common.base.Preconditions;
+import static com.google.common.base.Preconditions.checkArgument;
+
 import org.opendaylight.openflowplugin.extension.api.ConvertorActionFromOFJava;
 import org.opendaylight.openflowplugin.extension.api.ConvertorActionToOFJava;
 import org.opendaylight.openflowplugin.extension.api.path.ActionPath;
@@ -15,7 +16,6 @@ import org.opendaylight.openflowplugin.extension.vendor.nicira.convertor.CodecPr
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.Action;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.action.rev140421.action.container.action.choice.ActionRegLoad;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.action.rev140421.action.container.action.choice.ActionRegLoadBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.action.rev140421.ofj.nx.action.reg.load.grouping.NxActionRegLoad;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.action.rev140421.ofj.nx.action.reg.load.grouping.NxActionRegLoadBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.NxActionRegLoadGrouping;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.flows.statistics.update.flow.and.statistics.map.list.instructions.instruction.instruction.apply.actions._case.apply.actions.action.action.NxActionRegLoadNotifFlowsStatisticsUpdateApplyActionsCaseBuilder;
@@ -27,7 +27,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.ni
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.nodes.node.table.flow.instructions.instruction.instruction.write.actions._case.write.actions.action.action.NxActionRegLoadNodesNodeTableFlowWriteActionsCaseBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.nx.action.reg.load.grouping.NxRegLoad;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.nx.action.reg.load.grouping.NxRegLoadBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.nx.action.reg.load.grouping.nx.reg.load.Dst;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.nx.action.reg.load.grouping.nx.reg.load.DstBuilder;
 import org.opendaylight.yangtools.yang.common.Uint16;
 
@@ -43,37 +42,34 @@ public class RegLoadConvertor implements
     @Override
     public Action convert(
             final org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action nxActionArg) {
-        Preconditions.checkArgument(nxActionArg instanceof NxActionRegLoadGrouping);
-
-        NxActionRegLoadGrouping nxAction = (NxActionRegLoadGrouping) nxActionArg;
-        Dst dst = nxAction.getNxRegLoad().getDst();
-
-
-        final ActionRegLoadBuilder actionRegLoadBuilder = new ActionRegLoadBuilder();
-        NxActionRegLoadBuilder nxActionRegLoadBuilder = new NxActionRegLoadBuilder();
-        // We resolve the destination as a uint32 header, reg load action
-        // does not support 8-byte experimenter headers.
-        nxActionRegLoadBuilder.setDst(FieldChoiceResolver.resolveDstHeaderUint32(dst.getDstChoice()));
-
+        checkArgument(nxActionArg instanceof NxActionRegLoadGrouping);
+        final var nxAction = (NxActionRegLoadGrouping) nxActionArg;
+        final var dst = nxAction.getNxRegLoad().getDst();
         final int start = dst.getStart().toJava();
-        nxActionRegLoadBuilder.setOfsNbits(Uint16.valueOf(start << 6 | dst.getEnd().toJava() - start));
-        nxActionRegLoadBuilder.setValue(nxAction.getNxRegLoad().getValue());
-        actionRegLoadBuilder.setNxActionRegLoad(nxActionRegLoadBuilder.build());
-        return ActionUtil.createAction(actionRegLoadBuilder.build());
+
+        return ActionUtil.createAction(new ActionRegLoadBuilder()
+            .setNxActionRegLoad(new NxActionRegLoadBuilder()
+                // We resolve the destination as a uint32 header, reg load action
+                // does not support 8-byte experimenter headers.
+                .setDst(FieldChoiceResolver.resolveDstHeaderUint32(dst.getDstChoice()))
+                .setOfsNbits(Uint16.valueOf(start << 6 | dst.getEnd().toJava() - start))
+                .setValue(nxAction.getNxRegLoad().getValue())
+                .build())
+            .build());
     }
 
     @Override
     public org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action convert(
             final Action input, final ActionPath path) {
-        NxActionRegLoad actionRegLoad = ((ActionRegLoad) input.getActionChoice()).getNxActionRegLoad();
-        DstBuilder dstBuilder = new DstBuilder();
-        dstBuilder.setDstChoice(FieldChoiceResolver.resolveDstChoice(actionRegLoad.getDst()));
-        dstBuilder.setStart(resolveStart(actionRegLoad.getOfsNbits()));
-        dstBuilder.setEnd(resolveEnd(actionRegLoad.getOfsNbits()));
-        NxRegLoadBuilder nxRegLoadBuilder = new NxRegLoadBuilder();
-        nxRegLoadBuilder.setDst(dstBuilder.build());
-        nxRegLoadBuilder.setValue(actionRegLoad.getValue());
-        return resolveAction(nxRegLoadBuilder.build(), path);
+        final var actionRegLoad = ((ActionRegLoad) input.getActionChoice()).getNxActionRegLoad();
+        return resolveAction(new NxRegLoadBuilder()
+            .setDst(new DstBuilder()
+                .setDstChoice(FieldChoiceResolver.resolveDstChoice(actionRegLoad.getDst()))
+                .setStart(resolveStart(actionRegLoad.getOfsNbits()))
+                .setEnd(resolveEnd(actionRegLoad.getOfsNbits()))
+                .build())
+            .setValue(actionRegLoad.getValue())
+            .build(), path);
     }
 
     private static Uint16 resolveStart(final Uint16 ofsNBints) {
index 0e52f0f186e61e73c0dc82a772ca2cea53d220e8..223cd945159318e476b5e4f658c2d8564cd6229e 100644 (file)
@@ -7,7 +7,8 @@
  */
 package org.opendaylight.openflowplugin.extension.vendor.nicira.convertor.action;
 
-import com.google.common.base.Preconditions;
+import static com.google.common.base.Preconditions.checkArgument;
+
 import org.opendaylight.openflowplugin.extension.api.ConvertorActionFromOFJava;
 import org.opendaylight.openflowplugin.extension.api.ConvertorActionToOFJava;
 import org.opendaylight.openflowplugin.extension.api.path.ActionPath;
@@ -15,7 +16,6 @@ import org.opendaylight.openflowplugin.extension.vendor.nicira.convertor.CodecPr
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.Action;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.action.rev140421.action.container.action.choice.ActionRegMove;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.action.rev140421.action.container.action.choice.ActionRegMoveBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.action.rev140421.ofj.nx.action.reg.move.grouping.NxActionRegMove;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.action.rev140421.ofj.nx.action.reg.move.grouping.NxActionRegMoveBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.NxActionRegMoveGrouping;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.flows.statistics.update.flow.and.statistics.map.list.instructions.instruction.instruction.apply.actions._case.apply.actions.action.action.NxActionRegMoveNotifFlowsStatisticsUpdateApplyActionsCaseBuilder;
@@ -31,6 +31,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.ni
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.nx.action.reg.move.grouping.nx.reg.move.DstBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.nx.action.reg.move.grouping.nx.reg.move.Src;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.nx.action.reg.move.grouping.nx.reg.move.SrcBuilder;
+import org.opendaylight.yangtools.yang.common.Uint16;
 
 /**
  * Convert to/from SAL flow model to openflowjava model for NxActionRegMove action.
@@ -46,44 +47,45 @@ public class RegMoveConvertor implements
 
     @Override
     public Action convert(
-            org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action nxActionArg) {
-        Preconditions.checkArgument(nxActionArg instanceof NxActionRegMoveGrouping);
-        NxActionRegMoveGrouping nxAction = (NxActionRegMoveGrouping) nxActionArg;
-
-        Dst dst = nxAction.getNxRegMove().getDst();
-        Src src = nxAction.getNxRegMove().getSrc();
-        final ActionRegMoveBuilder actionRegMoveBuilder = new ActionRegMoveBuilder();
-        NxActionRegMoveBuilder nxActionRegMove = new NxActionRegMoveBuilder();
+            final org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action nxActionArg) {
+        checkArgument(nxActionArg instanceof NxActionRegMoveGrouping);
+        final NxActionRegMoveGrouping nxAction = (NxActionRegMoveGrouping) nxActionArg;
+        final Dst dst = nxAction.getNxRegMove().getDst();
+        final Src src = nxAction.getNxRegMove().getSrc();
 
-        nxActionRegMove.setDst(FieldChoiceResolver.resolveDstHeaderUint64(dst.getDstChoice()));
-        nxActionRegMove.setDstOfs(dst.getStart());
-        nxActionRegMove.setSrc(FieldChoiceResolver.resolveSrcHeaderUint64(src.getSrcChoice()));
-        nxActionRegMove.setSrcOfs(src.getStart());
-        nxActionRegMove.setNBits(dst.getEnd().toJava() - dst.getStart().toJava() + 1);
-        actionRegMoveBuilder.setNxActionRegMove(nxActionRegMove.build());
-        return ActionUtil.createAction(actionRegMoveBuilder.build());
+        return ActionUtil.createAction(new ActionRegMoveBuilder()
+            .setNxActionRegMove(new NxActionRegMoveBuilder()
+                .setDst(FieldChoiceResolver.resolveDstHeaderUint64(dst.getDstChoice()))
+                .setDstOfs(dst.getStart())
+                .setSrc(FieldChoiceResolver.resolveSrcHeaderUint64(src.getSrcChoice()))
+                .setSrcOfs(src.getStart())
+                .setNBits(Uint16.valueOf(dst.getEnd().toJava() - dst.getStart().toJava() + 1))
+                .build())
+            .build());
     }
 
     @Override
     public org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action convert(
-            Action input, ActionPath path) {
-        NxActionRegMove actionRegMove = ((ActionRegMove) input.getActionChoice()).getNxActionRegMove();
-        DstBuilder dstBuilder = new DstBuilder();
-        dstBuilder.setDstChoice(FieldChoiceResolver.resolveDstChoice(actionRegMove.getDst()));
-        dstBuilder.setStart(actionRegMove.getDstOfs());
-        dstBuilder.setEnd(actionRegMove.getDstOfs().toJava() + actionRegMove.getNBits().toJava() - 1);
-        SrcBuilder srcBuilder = new SrcBuilder();
-        srcBuilder.setSrcChoice(FieldChoiceResolver.resolveSrcChoice(actionRegMove.getSrc()));
-        srcBuilder.setStart(actionRegMove.getSrcOfs());
-        srcBuilder.setEnd(actionRegMove.getSrcOfs().toJava() + actionRegMove.getNBits().toJava() - 1);
-        NxRegMoveBuilder nxRegMoveBuilder = new NxRegMoveBuilder();
-        nxRegMoveBuilder.setDst(dstBuilder.build());
-        nxRegMoveBuilder.setSrc(srcBuilder.build());
-        return resolveAction(nxRegMoveBuilder.build(), path);
+            final Action input, final ActionPath path) {
+        final var actionRegMove = ((ActionRegMove) input.getActionChoice()).getNxActionRegMove();
+        final int delta = actionRegMove.getNBits().toJava() - 1;
+
+        return resolveAction(new NxRegMoveBuilder()
+            .setDst(new DstBuilder()
+                .setDstChoice(FieldChoiceResolver.resolveDstChoice(actionRegMove.getDst()))
+                .setStart(actionRegMove.getDstOfs())
+                .setEnd(Uint16.valueOf(actionRegMove.getDstOfs().toJava() + delta))
+                .build())
+            .setSrc(new SrcBuilder()
+                .setSrcChoice(FieldChoiceResolver.resolveSrcChoice(actionRegMove.getSrc()))
+                .setStart(actionRegMove.getSrcOfs())
+                .setEnd(Uint16.valueOf(actionRegMove.getSrcOfs().toJava() + delta))
+                .build())
+            .build(), path);
     }
 
     private static org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action resolveAction(
-            NxRegMove value, ActionPath path) {
+            final NxRegMove value, final ActionPath path) {
         switch (path) {
             case INVENTORY_FLOWNODE_TABLE_WRITE_ACTIONS:
                 return new NxActionRegMoveNodesNodeTableFlowWriteActionsCaseBuilder().setNxRegMove(value).build();
index 04101b5ca3ace71e462f925cf185b7660e43d881..6365f50f39be97174419a28d153ef3a2f068082a 100644 (file)
@@ -37,6 +37,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.ni
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.nxm.of.arp.spa.grouping.NxmOfArpSpa;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.nxm.of.arp.spa.grouping.NxmOfArpSpaBuilder;
 import org.opendaylight.yangtools.yang.binding.Augmentation;
+import org.opendaylight.yangtools.yang.common.Uint32;
 
 /**
  * Convert to/from SAL flow model to openflowjava model for ArpSpaCase.
@@ -59,12 +60,15 @@ public class ArpSpaConvertor implements ConvertorToOFJava<MatchEntry>, Convertor
         if (!matchGrouping.isPresent()) {
             throw new CodecPreconditionException(extension);
         }
-        Long value = IpConverter.ipv4AddressToLong(matchGrouping.get().getNxmOfArpSpa().getIpv4Address());
-        ArpSpaCaseValueBuilder arpSpaCaseValueBuilder = new ArpSpaCaseValueBuilder();
-        arpSpaCaseValueBuilder.setArpSpaValues(new ArpSpaValuesBuilder()
-                .setValue(value).build());
-        return MatchUtil.createDefaultMatchEntryBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx
-                .match.rev140421.NxmOfArpSpa.class, Nxm0Class.class, arpSpaCaseValueBuilder.build()).build();
+        return MatchUtil.createDefaultMatchEntryBuilder(
+            org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.NxmOfArpSpa.class,
+            Nxm0Class.class, new ArpSpaCaseValueBuilder()
+                .setArpSpaValues(new ArpSpaValuesBuilder()
+                    .setValue(Uint32.valueOf(IpConverter.ipv4AddressToLong(matchGrouping.get().getNxmOfArpSpa()
+                        .getIpv4Address())))
+                    .build())
+                .build())
+            .build();
     }
 
     private static ExtensionAugment<? extends Augmentation<Extension>> resolveAugmentation(final NxmOfArpSpa value,
index 20771cc33e991d2873444aa10a0c1d68080a8d93..bc362dfc0a0044b6063ad17da466a2620692eaf0 100644 (file)
@@ -37,6 +37,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.ni
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.nxm.of.arp.tpa.grouping.NxmOfArpTpa;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.nxm.of.arp.tpa.grouping.NxmOfArpTpaBuilder;
 import org.opendaylight.yangtools.yang.binding.Augmentation;
+import org.opendaylight.yangtools.yang.common.Uint32;
 
 /**
  * Convert to/from SAL flow model to openflowjava model for ArpTpaCase.
@@ -46,7 +47,7 @@ import org.opendaylight.yangtools.yang.binding.Augmentation;
 public class ArpTpaConvertor implements ConvertorToOFJava<MatchEntry>, ConvertorFromOFJava<MatchEntry, MatchPath> {
 
     @Override
-    public ExtensionAugment<? extends Augmentation<Extension>> convert(MatchEntry input, MatchPath path) {
+    public ExtensionAugment<? extends Augmentation<Extension>> convert(final MatchEntry input, final MatchPath path) {
         ArpTpaCaseValue arpTpaCaseValue = (ArpTpaCaseValue) input.getMatchEntryValue();
         Ipv4Address ipv4Address = IpConverter.longToIpv4Address(arpTpaCaseValue.getArpTpaValues().getValue());
         return resolveAugmentation(new NxmOfArpTpaBuilder().setIpv4Address(ipv4Address).build(), path,
@@ -54,22 +55,23 @@ public class ArpTpaConvertor implements ConvertorToOFJava<MatchEntry>, Convertor
     }
 
     @Override
-    public MatchEntry convert(Extension extension) {
+    public MatchEntry convert(final Extension extension) {
         Optional<NxmOfArpTpaGrouping> matchGrouping = MatchUtil.ARP_TPA_RESOLVER.findExtension(extension);
         if (!matchGrouping.isPresent()) {
             throw new CodecPreconditionException(extension);
         }
-        Long value = IpConverter.ipv4AddressToLong(matchGrouping.get().getNxmOfArpTpa().getIpv4Address());
-        ArpTpaCaseValueBuilder arpTpaCaseValueBuilder = new ArpTpaCaseValueBuilder();
-        arpTpaCaseValueBuilder.setArpTpaValues(new ArpTpaValuesBuilder()
-                .setValue(value).build());
         return MatchUtil.createDefaultMatchEntryBuilder(
-                org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.NxmOfArpTpa.class,
-                Nxm0Class.class, arpTpaCaseValueBuilder.build()).build();
+            org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.NxmOfArpTpa.class,
+            Nxm0Class.class, new ArpTpaCaseValueBuilder()
+                .setArpTpaValues(new ArpTpaValuesBuilder()
+                    .setValue(Uint32.valueOf(
+                        IpConverter.ipv4AddressToLong(matchGrouping.get().getNxmOfArpTpa().getIpv4Address()))).build())
+                .build())
+            .build();
     }
 
-    private static ExtensionAugment<? extends Augmentation<Extension>> resolveAugmentation(NxmOfArpTpa value,
-            MatchPath path, Class<? extends ExtensionKey> key) {
+    private static ExtensionAugment<? extends Augmentation<Extension>> resolveAugmentation(final NxmOfArpTpa value,
+            final MatchPath path, final Class<? extends ExtensionKey> key) {
         switch (path) {
             case FLOWS_STATISTICS_UPDATE_MATCH:
                 return new ExtensionAugment<>(NxAugMatchNodesNodeTableFlow.class,
index 67248e1cd847fb2507b0025ef7348dd2dc42d385..caa005feff59f60b75b6613ef6f6799c3bdb15db 100644 (file)
@@ -7,14 +7,10 @@
  */
 package org.opendaylight.openflowplugin.extension.vendor.nicira.convertor.match;
 
-import com.google.common.base.Joiner;
-import com.google.common.base.Splitter;
 import com.google.common.collect.ImmutableSet;
-import com.google.common.primitives.Longs;
-import com.google.common.primitives.UnsignedBytes;
-import java.util.Iterator;
 import org.opendaylight.openflowplugin.extension.api.AugmentationGroupingResolver;
 import org.opendaylight.openflowplugin.extension.api.AugmentationGroupingResolver.Factory;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IetfInetUtil;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev150225.oxm.container.match.entry.value.ExperimenterIdCase;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev150225.oxm.container.match.entry.value.ExperimenterIdCaseBuilder;
@@ -78,9 +74,6 @@ import org.opendaylight.yangtools.yang.common.Uint32;
  * @author msunal
  */
 public final class MatchUtil {
-    private static final Splitter SPLITTER = Splitter.on('.');
-    private static final Joiner JOINER = Joiner.on('.');
-
     public static final AugmentationGroupingResolver<NxmNxRegGrouping, Extension> REG_RESOLVER;
     public static final AugmentationGroupingResolver<NxmNxTunIdGrouping, Extension> TUN_ID_RESOLVER;
     public static final AugmentationGroupingResolver<NxmNxArpShaGrouping, Extension> ARP_SHA_RESOLVER;
@@ -163,17 +156,17 @@ public final class MatchUtil {
     }
 
     private MatchUtil() {
+        // Hidden on purpose
     }
 
     public static MatchEntryBuilder createDefaultMatchEntryBuilder(final Class<? extends MatchField> matchField,
                                                                    final Class<? extends OxmClassBase> oxmClass,
                                                                    final MatchEntryValue matchEntryValue) {
-        MatchEntryBuilder matchEntryBuilder = new MatchEntryBuilder();
-        matchEntryBuilder.setHasMask(false);
-        matchEntryBuilder.setOxmMatchField(matchField);
-        matchEntryBuilder.setOxmClass(oxmClass);
-        matchEntryBuilder.setMatchEntryValue(matchEntryValue);
-        return matchEntryBuilder;
+        return new MatchEntryBuilder()
+            .setHasMask(false)
+            .setOxmMatchField(matchField)
+            .setOxmClass(oxmClass)
+            .setMatchEntryValue(matchEntryValue);
     }
 
     public static <V extends Augmentation<ExperimenterIdCase>> MatchEntryBuilder createExperimenterMatchEntryBuilder(
@@ -186,36 +179,11 @@ public final class MatchUtil {
             .build());
     }
 
-    public static Long ipv4ToLong(final Ipv4Address ipv4) {
-        Iterator<String> iterator = SPLITTER.split(ipv4.getValue()).iterator();
-        byte[] bytes = new byte[8];
-        for (int i = 0; i < bytes.length; i++) {
-            if (i < 4) {
-                bytes[i] = 0;
-            } else {
-                bytes[i] = UnsignedBytes.parseUnsignedByte(iterator.next());
-            }
-        }
-        Long result = Longs.fromByteArray(bytes);
-        return result;
-    }
-
-    public static Ipv4Address longToIpv4Address(final Uint32 value) {
-        return longToIpv4Address(value.toJava());
-    }
-
-    public static Ipv4Address longToIpv4Address(final Long value) {
-        return longToIpv4Address(value.longValue());
+    public static Uint32 ipv4ToUint32(final Ipv4Address ipv4) {
+        return Uint32.fromIntBits(IetfInetUtil.INSTANCE.ipv4AddressBits(ipv4));
     }
 
-    public static Ipv4Address longToIpv4Address(final long value) {
-        byte[] bytes = Longs.toByteArray(value);
-        String[] strArray = new String[4];
-        for (int i = 4; i < bytes.length; i++) {
-            strArray[i - 4] = UnsignedBytes.toString(bytes[i]);
-        }
-        String str = JOINER.join(strArray);
-        Ipv4Address result = new Ipv4Address(str);
-        return result;
+    public static Ipv4Address uint32ToIpv4Address(final Uint32 value) {
+        return IetfInetUtil.INSTANCE.ipv4AddressFor(value.intValue());
     }
 }
index a34cc688ff12c7110e2bcbc56c9302d7ea9a15c6..aaadafa950070a86e4651617097aad0518c3a2e2 100644 (file)
@@ -7,7 +7,6 @@
  */
 package org.opendaylight.openflowplugin.extension.vendor.nicira.convertor.match;
 
-import java.util.Optional;
 import org.opendaylight.openflowplugin.extension.api.ConvertorFromOFJava;
 import org.opendaylight.openflowplugin.extension.api.ConvertorToOFJava;
 import org.opendaylight.openflowplugin.extension.api.ExtensionAugment;
@@ -31,15 +30,14 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.ni
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchPacketInMessageBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchRpcGetFlowStats;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchRpcGetFlowStatsBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxmNxTunIpv4DstGrouping;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxmNxTunIpv4DstKey;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.nxm.nx.tun.ipv4.dst.grouping.NxmNxTunIpv4Dst;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.nxm.nx.tun.ipv4.dst.grouping.NxmNxTunIpv4DstBuilder;
 import org.opendaylight.yangtools.yang.binding.Augmentation;
 
 public class TunIPv4DstConvertor implements ConvertorToOFJava<MatchEntry>, ConvertorFromOFJava<MatchEntry, MatchPath> {
-    private static ExtensionAugment<? extends Augmentation<Extension>> resolveAugmentation(NxmNxTunIpv4Dst value,
-            MatchPath path, Class<? extends ExtensionKey> key) {
+    private static ExtensionAugment<? extends Augmentation<Extension>> resolveAugmentation(final NxmNxTunIpv4Dst value,
+            final MatchPath path, final Class<? extends ExtensionKey> key) {
         switch (path) {
             case FLOWS_STATISTICS_UPDATE_MATCH:
                 return new ExtensionAugment<>(NxAugMatchNodesNodeTableFlow.class,
@@ -63,26 +61,26 @@ public class TunIPv4DstConvertor implements ConvertorToOFJava<MatchEntry>, Conve
 
     @Override
     public ExtensionAugment<? extends Augmentation<Extension>> convert(
-            MatchEntry input, MatchPath path) {
+            final MatchEntry input, final MatchPath path) {
         TunIpv4DstCaseValue tunIpv4DstCaseValue = (TunIpv4DstCaseValue) input.getMatchEntryValue();
         return resolveAugmentation(new NxmNxTunIpv4DstBuilder()
-                .setIpv4Address(MatchUtil.longToIpv4Address(tunIpv4DstCaseValue.getTunIpv4DstValues().getValue()))
+                .setIpv4Address(MatchUtil.uint32ToIpv4Address(tunIpv4DstCaseValue.getTunIpv4DstValues().getValue()))
                 .build(), path, NxmNxTunIpv4DstKey.class);
     }
 
     @Override
-    public MatchEntry convert(Extension extension) {
-        Optional<NxmNxTunIpv4DstGrouping> matchGrouping = MatchUtil.TUN_IPV4_DST_RESOLVER.findExtension(extension);
-        if (!matchGrouping.isPresent()) {
-            throw new CodecPreconditionException(extension);
-        }
-        Ipv4Address value = matchGrouping.get().getNxmNxTunIpv4Dst().getIpv4Address();
+    public MatchEntry convert(final Extension extension) {
+        final Ipv4Address value = MatchUtil.TUN_IPV4_DST_RESOLVER.findExtension(extension)
+            .orElseThrow(() -> new CodecPreconditionException(extension))
+            .getNxmNxTunIpv4Dst().getIpv4Address();
 
-        TunIpv4DstCaseValueBuilder tunIpv4DstCaseValueBuilder = new TunIpv4DstCaseValueBuilder();
-        tunIpv4DstCaseValueBuilder.setTunIpv4DstValues(new TunIpv4DstValuesBuilder()
-                .setValue(MatchUtil.ipv4ToLong(value)).build());
         return MatchUtil.createDefaultMatchEntryBuilder(
-                org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.NxmNxTunIpv4Dst.class,
-                Nxm1Class.class, tunIpv4DstCaseValueBuilder.build()).build();
+            org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.NxmNxTunIpv4Dst.class,
+            Nxm1Class.class, new TunIpv4DstCaseValueBuilder()
+                .setTunIpv4DstValues(new TunIpv4DstValuesBuilder()
+                    .setValue(MatchUtil.ipv4ToUint32(value))
+                    .build())
+                .build())
+            .build();
     }
 }
index 9da50d600ada637d14ff5923d3019035e2518007..e5e31392db0e759a570e75536a3a71fd35c6c899 100644 (file)
@@ -7,7 +7,6 @@
  */
 package org.opendaylight.openflowplugin.extension.vendor.nicira.convertor.match;
 
-import java.util.Optional;
 import org.opendaylight.openflowplugin.extension.api.ConvertorFromOFJava;
 import org.opendaylight.openflowplugin.extension.api.ConvertorToOFJava;
 import org.opendaylight.openflowplugin.extension.api.ExtensionAugment;
@@ -31,15 +30,14 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.ni
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchPacketInMessageBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchRpcGetFlowStats;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchRpcGetFlowStatsBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxmNxTunIpv4SrcGrouping;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxmNxTunIpv4SrcKey;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.nxm.nx.tun.ipv4.src.grouping.NxmNxTunIpv4Src;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.nxm.nx.tun.ipv4.src.grouping.NxmNxTunIpv4SrcBuilder;
 import org.opendaylight.yangtools.yang.binding.Augmentation;
 
 public class TunIPv4SrcConvertor implements ConvertorToOFJava<MatchEntry>, ConvertorFromOFJava<MatchEntry, MatchPath> {
-    private static ExtensionAugment<? extends Augmentation<Extension>> resolveAugmentation(NxmNxTunIpv4Src value,
-            MatchPath path, Class<? extends ExtensionKey> key) {
+    private static ExtensionAugment<? extends Augmentation<Extension>> resolveAugmentation(final NxmNxTunIpv4Src value,
+            final MatchPath path, final Class<? extends ExtensionKey> key) {
         switch (path) {
             case FLOWS_STATISTICS_UPDATE_MATCH:
                 return new ExtensionAugment<>(NxAugMatchNodesNodeTableFlow.class,
@@ -63,26 +61,26 @@ public class TunIPv4SrcConvertor implements ConvertorToOFJava<MatchEntry>, Conve
 
     @Override
     public ExtensionAugment<? extends Augmentation<Extension>> convert(
-            MatchEntry input, MatchPath path) {
+            final MatchEntry input, final MatchPath path) {
         TunIpv4SrcCaseValue tunIpv4SrcCaseValue = (TunIpv4SrcCaseValue) input.getMatchEntryValue();
         return resolveAugmentation(new NxmNxTunIpv4SrcBuilder()
-                .setIpv4Address(MatchUtil.longToIpv4Address(tunIpv4SrcCaseValue.getTunIpv4SrcValues().getValue()))
+                .setIpv4Address(MatchUtil.uint32ToIpv4Address(tunIpv4SrcCaseValue.getTunIpv4SrcValues().getValue()))
                 .build(), path, NxmNxTunIpv4SrcKey.class);
     }
 
     @Override
-    public MatchEntry convert(Extension extension) {
-        Optional<NxmNxTunIpv4SrcGrouping> matchGrouping = MatchUtil.TUN_IPV4_SRC_RESOLVER.findExtension(extension);
-        if (!matchGrouping.isPresent()) {
-            throw new CodecPreconditionException(extension);
-        }
-        Ipv4Address value = matchGrouping.get().getNxmNxTunIpv4Src().getIpv4Address();
+    public MatchEntry convert(final Extension extension) {
+        final Ipv4Address value = MatchUtil.TUN_IPV4_SRC_RESOLVER.findExtension(extension)
+            .orElseThrow(() -> new CodecPreconditionException(extension))
+            .getNxmNxTunIpv4Src().getIpv4Address();
 
-        TunIpv4SrcCaseValueBuilder tunIpv4SrcCaseValueBuilder = new TunIpv4SrcCaseValueBuilder();
-        tunIpv4SrcCaseValueBuilder.setTunIpv4SrcValues(new TunIpv4SrcValuesBuilder()
-                .setValue(MatchUtil.ipv4ToLong(value)).build());
         return MatchUtil.createDefaultMatchEntryBuilder(
-                org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.NxmNxTunIpv4Src.class,
-                Nxm1Class.class, tunIpv4SrcCaseValueBuilder.build()).build();
+            org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.NxmNxTunIpv4Src.class,
+            Nxm1Class.class, new TunIpv4SrcCaseValueBuilder()
+                .setTunIpv4SrcValues(new TunIpv4SrcValuesBuilder()
+                    .setValue(MatchUtil.ipv4ToUint32(value))
+                    .build())
+                .build())
+            .build();
     }
 }
index ad80ede17db31a55e1caae22e6f3ce3643a0d8a4..8d7034ab14b3588b3a54affd908cf47d7fe7138b 100644 (file)
@@ -12,22 +12,19 @@ import static org.junit.Assert.assertEquals;
 import org.junit.Test;
 import org.opendaylight.openflowplugin.extension.vendor.nicira.convertor.match.MatchUtil;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
+import org.opendaylight.yangtools.yang.common.Uint32;
 
 public class MatchUtilTest {
-
     private static final Ipv4Address IPV4_ADDRESS = new Ipv4Address("1.2.3.4");
-    private static final Long IPV4_LONG = 16909060L;
+    private static final Uint32 IPV4_LONG = Uint32.valueOf(16909060);
 
     @Test
     public void testIpv4toLong() {
-        final Long result = MatchUtil.ipv4ToLong(IPV4_ADDRESS);
-        assertEquals("Does not match",IPV4_LONG,result);
+        assertEquals(IPV4_LONG, MatchUtil.ipv4ToUint32(IPV4_ADDRESS));
     }
 
     @Test
     public void testLongtoIpv4() {
-        Ipv4Address result = MatchUtil.longToIpv4Address(16909060L);
-        assertEquals("Does not match",IPV4_ADDRESS,result);
+        assertEquals(IPV4_ADDRESS, MatchUtil.uint32ToIpv4Address(IPV4_LONG));
     }
-
 }