Fix deprecation warnings in learning-switch 70/92370/4
authorRobert Varga <robert.varga@pantheon.tech>
Wed, 2 Sep 2020 09:40:58 +0000 (11:40 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Mon, 7 Sep 2020 08:12:52 +0000 (10:12 +0200)
Convert use of both legacy lists as well as widened types,
eliminating deprecation warnings.

JIRA: OPNFLWPLUG-1099
Change-Id: I6a5d994a96f37a7342517e4adc133d4f8579cc30
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
samples/learning-switch/src/main/java/org/opendaylight/openflowplugin/learningswitch/FlowUtils.java
samples/learning-switch/src/main/java/org/opendaylight/openflowplugin/learningswitch/LearningSwitchHandlerSimpleImpl.java

index 03e600ca515a042e364025e17faca724a67392f4..bcb850c2c5016fea59d5d954abbcde999aedba94 100644 (file)
@@ -5,12 +5,9 @@
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
  * and is available at http://www.eclipse.org/legal/epl-v10.html
  */
-
 package org.opendaylight.openflowplugin.learningswitch;
 
-import com.google.common.collect.ImmutableList;
-import java.util.ArrayList;
-import java.util.List;
+import java.util.Map;
 import org.opendaylight.openflowplugin.api.OFConstants;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Uri;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress;
@@ -49,8 +46,8 @@ public final class FlowUtils {
     /**
      * Returns a {@link FlowBuilder} forwarding all packets to controller port.
      */
-    public static FlowBuilder createDirectMacToMacFlow(final Uint8 tableId, final int priority, final MacAddress srcMac,
-            final MacAddress dstMac, final NodeConnectorRef dstPort) {
+    public static FlowBuilder createDirectMacToMacFlow(final Uint8 tableId, final Uint16 priority,
+            final MacAddress srcMac, final MacAddress dstMac, final NodeConnectorRef dstPort) {
         FlowBuilder macToMacFlow = new FlowBuilder()
                 .setTableId(tableId)
                 .setFlowName("mac2mac");
@@ -81,7 +78,8 @@ public final class FlowUtils {
                 .build();
 
         // Create an Apply Action
-        ApplyActions applyActions = new ApplyActionsBuilder().setAction(ImmutableList.of(outputToControllerAction))
+        ApplyActions applyActions = new ApplyActionsBuilder()
+                .setAction(Map.of(outputToControllerAction.key(), outputToControllerAction))
                 .build();
 
         // Wrap our Apply Action in an Instruction
@@ -99,12 +97,12 @@ public final class FlowUtils {
                         .setEthernetMatch(ethernetMatch)
                         .build())
                 .setInstructions(new InstructionsBuilder()
-                        .setInstruction(ImmutableList.of(applyActionsInstruction))
+                        .setInstruction(Map.of(applyActionsInstruction.key(), applyActionsInstruction))
                         .build())
                 .setPriority(priority)
                 .setBufferId(OFConstants.OFP_NO_BUFFER)
-                .setHardTimeout(0)
-                .setIdleTimeout(0)
+                .setHardTimeout(Uint16.ZERO)
+                .setIdleTimeout(Uint16.ZERO)
                 .setFlags(new FlowModFlags(false, false, false, false, false));
 
         return macToMacFlow;
@@ -113,7 +111,7 @@ public final class FlowUtils {
     /**
      * Returns a{@link FlowBuilder} forwarding all packets to controller port.
      */
-    public static FlowBuilder createFwdAllToControllerFlow(final Uint8 tableId, final int priority,
+    public static FlowBuilder createFwdAllToControllerFlow(final Uint8 tableId, final Uint16 priority,
             final FlowId flowId) {
         // Create output action -> send to controller
         OutputActionBuilder output = new OutputActionBuilder();
@@ -121,29 +119,23 @@ public final class FlowUtils {
         Uri controllerPort = new Uri(OutputPortValues.CONTROLLER.toString());
         output.setOutputNodeConnector(controllerPort);
 
-        ActionBuilder ab = new ActionBuilder();
-        ab.setAction(new OutputActionCaseBuilder().setOutputAction(output.build()).build());
-        ab.setOrder(0);
-        ab.withKey(new ActionKey(0));
-
-        List<Action> actionList = new ArrayList<>();
-        actionList.add(ab.build());
+        Action action = new ActionBuilder()
+                .setAction(new OutputActionCaseBuilder().setOutputAction(output.build()).build())
+                .withKey(new ActionKey(0))
+                .build();
 
         // Create an Apply Action
-        ApplyActionsBuilder aab = new ApplyActionsBuilder();
-        aab.setAction(actionList);
+        ApplyActionsBuilder aab = new ApplyActionsBuilder().setAction(Map.of(action.key(), action));
 
         // Wrap our Apply Action in an Instruction
-        InstructionBuilder ib = new InstructionBuilder();
-        ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
-        ib.setOrder(0);
-        ib.withKey(new InstructionKey(0));
+        Instruction instruction = new InstructionBuilder()
+                .setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build())
+                .withKey(new InstructionKey(0))
+                .build();
 
         // Put our Instruction in a list of Instructions
-        InstructionsBuilder isb = new InstructionsBuilder();
-        List<Instruction> instructions = new ArrayList<>();
-        instructions.add(ib.build());
-        isb.setInstruction(instructions);
+        InstructionsBuilder isb = new InstructionsBuilder()
+                .setInstruction(Map.of(instruction.key(), instruction));
 
         MatchBuilder matchBuilder = new MatchBuilder();
         FlowBuilder allToCtrlFlow = new FlowBuilder().setTableId(tableId).setFlowName("allPacketsToCtrl").setId(flowId)
@@ -153,8 +145,8 @@ public final class FlowUtils {
             .setInstructions(isb.build())
             .setPriority(priority)
             .setBufferId(OFConstants.OFP_NO_BUFFER)
-            .setHardTimeout(0)
-            .setIdleTimeout(0)
+            .setHardTimeout(Uint16.ZERO)
+            .setIdleTimeout(Uint16.ZERO)
             .setFlags(new FlowModFlags(false, false, false, false, false));
 
         return allToCtrlFlow;
index efbca47ebea7dd6b6d5b0d81d9f51ffe6bde53e7..3b8b4b09b0e369dc0d183d81107f514c3ad0cedf 100644 (file)
@@ -7,7 +7,6 @@
  */
 package org.opendaylight.openflowplugin.learningswitch;
 
-import java.math.BigInteger;
 import java.nio.ByteBuffer;
 import java.util.Arrays;
 import java.util.HashMap;
@@ -40,6 +39,8 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.Pa
 import org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.TransmitPacketInput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.TransmitPacketInputBuilder;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.opendaylight.yangtools.yang.common.Uint16;
+import org.opendaylight.yangtools.yang.common.Uint64;
 import org.opendaylight.yangtools.yang.common.Uint8;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -51,7 +52,7 @@ public class LearningSwitchHandlerSimpleImpl implements LearningSwitchHandler, P
 
     private static final Logger LOG = LoggerFactory.getLogger(LearningSwitchHandlerSimpleImpl.class);
     private static final byte[] ETH_TYPE_IPV4 = new byte[] { 0x08, 0x00 };
-    private static final int DIRECT_FLOW_PRIORITY = 512;
+    private static final Uint16 DIRECT_FLOW_PRIORITY = Uint16.valueOf(512);
 
     private final DataTreeChangeListenerRegistrationHolder registrationPublisher;
     private final FlowCommitWrapper dataStoreAccessor;
@@ -104,7 +105,7 @@ public class LearningSwitchHandlerSimpleImpl implements LearningSwitchHandler, P
         FlowKey flowKey = new FlowKey(flowId);
         InstanceIdentifier<Flow> flowPath = InstanceIdentifierUtils.createFlowPath(tablePath, flowKey);
 
-        int priority = 0;
+        Uint16 priority = Uint16.ZERO;
         // create flow in table with id = 0, priority = 4 (other params are
         // defaulted in OFDataStoreUtil)
         FlowBuilder allToCtrlFlow = FlowUtils.createFwdAllToControllerFlow(
@@ -194,7 +195,7 @@ public class LearningSwitchHandlerSimpleImpl implements LearningSwitchHandler, P
                 Uint8 tableId = InstanceIdentifierUtils.getTableId(tablePath);
                 FlowBuilder srcToDstFlow = FlowUtils.createDirectMacToMacFlow(tableId, DIRECT_FLOW_PRIORITY, srcMac,
                         dstMac, destNodeConnector);
-                srcToDstFlow.setCookie(new FlowCookie(BigInteger.valueOf(flowCookieInc.getAndIncrement())));
+                srcToDstFlow.setCookie(new FlowCookie(Uint64.valueOf(flowCookieInc.getAndIncrement())));
 
                 dataStoreAccessor.writeFlowToConfig(flowPath, srcToDstFlow.build());
             }