OPNFLWPLUG-1032: Neon-MRI: Bump odlparent, yangtools, mdsal
[openflowplugin.git] / samples / learning-switch / src / main / java / org / opendaylight / openflowplugin / learningswitch / FlowUtils.java
index a469992c3dbbeecb1fda36050fda935ef7c423ae..d799e8fe9beddb21023c21e83054b1d2719e64cd 100644 (file)
@@ -1,11 +1,19 @@
+/*
+ * Copyright (c) 2014, 2015 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * 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 org.opendaylight.openflowplugin.api.OFConstants;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Uri;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress;
+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;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.OutputActionCaseBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.output.action._case.OutputActionBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action;
@@ -26,52 +34,48 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instru
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.InstructionKey;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorRef;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnector;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnectorKey;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ethernet.match.fields.EthernetDestinationBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ethernet.match.fields.EthernetSourceBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.EthernetMatch;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.EthernetMatchBuilder;
 
-import com.google.common.collect.ImmutableList;
+public final class FlowUtils {
+    private FlowUtils() {
+        //prohibite to instantiate util class
+    }
 
-public class FlowUtils {
     /**
-     * @param tableId
-     * @param priority
-     * @param srcMac
-     * @param dstMac
-     * @param dstPort
-     * @return {@link FlowBuilder} forwarding all packets to controller port
+     * Returns a {@link FlowBuilder} forwarding all packets to controller port.
      */
     public static FlowBuilder createDirectMacToMacFlow(final Short tableId, final int priority, final MacAddress srcMac,
             final MacAddress dstMac, final NodeConnectorRef dstPort) {
-        FlowBuilder macToMacFlow = new FlowBuilder() //
-                .setTableId(tableId) //
+        FlowBuilder macToMacFlow = new FlowBuilder()
+                .setTableId(tableId)
                 .setFlowName("mac2mac");
         macToMacFlow.setId(new FlowId(Long.toString(macToMacFlow.hashCode())));
 
-        EthernetMatch ethernetMatch = new EthernetMatchBuilder() //
-                .setEthernetSource(new EthernetSourceBuilder() //
-                        .setAddress(srcMac) //
-                        .build()) //
-                .setEthernetDestination(new EthernetDestinationBuilder() //
-                        .setAddress(dstMac) //
-                        .build()) //
+        EthernetMatch ethernetMatch = new EthernetMatchBuilder()
+                .setEthernetSource(new EthernetSourceBuilder()
+                        .setAddress(srcMac)
+                        .build())
+                .setEthernetDestination(new EthernetDestinationBuilder()
+                        .setAddress(dstMac)
+                        .build())
                 .build();
 
         MatchBuilder match = new MatchBuilder();
         match.setEthernetMatch(ethernetMatch);
 
-        Uri outputPort = dstPort.getValue().firstKeyOf(NodeConnector.class, NodeConnectorKey.class).getId();
+        Uri outputPort = dstPort.getValue().firstKeyOf(NodeConnector.class).getId();
 
-        Action outputToControllerAction = new ActionBuilder() //
+        Action outputToControllerAction = new ActionBuilder()
                 .setOrder(0)
-                .setAction(new OutputActionCaseBuilder() //
-                        .setOutputAction(new OutputActionBuilder() //
-                                .setMaxLength(new Integer(0xffff)) //
-                                .setOutputNodeConnector(outputPort) //
-                                .build()) //
-                        .build()) //
+                .setAction(new OutputActionCaseBuilder()
+                        .setOutputAction(new OutputActionBuilder()
+                                .setMaxLength(Integer.valueOf(0xffff))
+                                .setOutputNodeConnector(outputPort)
+                                .build())
+                        .build())
                 .build();
 
         // Create an Apply Action
@@ -79,55 +83,48 @@ public class FlowUtils {
                 .build();
 
         // Wrap our Apply Action in an Instruction
-        Instruction applyActionsInstruction = new InstructionBuilder() //
+        Instruction applyActionsInstruction = new InstructionBuilder()
                 .setOrder(0)
-                .setInstruction(new ApplyActionsCaseBuilder()//
-                        .setApplyActions(applyActions) //
-                        .build()) //
+                .setInstruction(new ApplyActionsCaseBuilder()
+                        .setApplyActions(applyActions)
+                        .build())
                 .build();
 
         // Put our Instruction in a list of Instructions
 
-        macToMacFlow //
-                .setMatch(new MatchBuilder() //
-                        .setEthernetMatch(ethernetMatch) //
-                        .build()) //
-                .setInstructions(new InstructionsBuilder() //
-                        .setInstruction(ImmutableList.of(applyActionsInstruction)) //
-                        .build()) //
-                .setPriority(priority) //
-                .setBufferId(OFConstants.OFP_NO_BUFFER) //
-                .setHardTimeout(0) //
-                .setIdleTimeout(0) //
+        macToMacFlow
+                .setMatch(new MatchBuilder()
+                        .setEthernetMatch(ethernetMatch)
+                        .build())
+                .setInstructions(new InstructionsBuilder()
+                        .setInstruction(ImmutableList.of(applyActionsInstruction))
+                        .build())
+                .setPriority(priority)
+                .setBufferId(OFConstants.OFP_NO_BUFFER)
+                .setHardTimeout(0)
+                .setIdleTimeout(0)
                 .setFlags(new FlowModFlags(false, false, false, false, false));
 
         return macToMacFlow;
     }
 
     /**
-     * @param tableId
-     * @param priority
-     * @param flowId
-     * @return {@link FlowBuilder} forwarding all packets to controller port
+     * Returns a{@link FlowBuilder} forwarding all packets to controller port.
      */
-    public static FlowBuilder createFwdAllToControllerFlow(final Short tableId, final int priority, final FlowId flowId) {
-        FlowBuilder allToCtrlFlow = new FlowBuilder().setTableId(tableId).setFlowName("allPacketsToCtrl").setId(flowId)
-                .setKey(new FlowKey(flowId));
-
-        MatchBuilder matchBuilder = new MatchBuilder();
-
+    public static FlowBuilder createFwdAllToControllerFlow(final Short tableId, final int priority,
+            final FlowId flowId) {
         // Create output action -> send to controller
         OutputActionBuilder output = new OutputActionBuilder();
-        output.setMaxLength(new Integer(0xffff));
+        output.setMaxLength(Integer.valueOf(0xffff));
         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.setKey(new ActionKey(0));
+        ab.withKey(new ActionKey(0));
 
-        List<Action> actionList = new ArrayList<Action>();
+        List<Action> actionList = new ArrayList<>();
         actionList.add(ab.build());
 
         // Create an Apply Action
@@ -138,21 +135,24 @@ public class FlowUtils {
         InstructionBuilder ib = new InstructionBuilder();
         ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
         ib.setOrder(0);
-        ib.setKey(new InstructionKey(0));
+        ib.withKey(new InstructionKey(0));
 
         // Put our Instruction in a list of Instructions
         InstructionsBuilder isb = new InstructionsBuilder();
-        List<Instruction> instructions = new ArrayList<Instruction>();
+        List<Instruction> instructions = new ArrayList<>();
         instructions.add(ib.build());
         isb.setInstruction(instructions);
 
-        allToCtrlFlow //
-            .setMatch(matchBuilder.build()) //
-            .setInstructions(isb.build()) //
-            .setPriority(priority) //
-            .setBufferId(OFConstants.OFP_NO_BUFFER) //
-            .setHardTimeout(0) //
-            .setIdleTimeout(0) //
+        MatchBuilder matchBuilder = new MatchBuilder();
+        FlowBuilder allToCtrlFlow = new FlowBuilder().setTableId(tableId).setFlowName("allPacketsToCtrl").setId(flowId)
+                .withKey(new FlowKey(flowId));
+        allToCtrlFlow
+            .setMatch(matchBuilder.build())
+            .setInstructions(isb.build())
+            .setPriority(priority)
+            .setBufferId(OFConstants.OFP_NO_BUFFER)
+            .setHardTimeout(0)
+            .setIdleTimeout(0)
             .setFlags(new FlowModFlags(false, false, false, false, false));
 
         return allToCtrlFlow;