Upgrade ietf-{inet,yang}-types to 2013-07-15
[openflowplugin.git] / samples / learning-switch / src / main / java / org / opendaylight / openflowplugin / learningswitch / FlowUtils.java
index 5ea397f50b55d125135b58dbd794def74f89b273..aa44ea007f86ab93a420e0f07acf149a0167f6fb 100644 (file)
@@ -1,10 +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 java.util.ArrayList;
 import java.util.List;
 
-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.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;
 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;
@@ -34,6 +43,10 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026
 import com.google.common.collect.ImmutableList;
 
 public class FlowUtils {
+    private FlowUtils() {
+        //prohibite to instantiate util class
+    }
+
     /**
      * @param tableId
      * @param priority
@@ -42,20 +55,20 @@ public class FlowUtils {
      * @param dstPort
      * @return {@link FlowBuilder} forwarding all packets to controller port
      */
-    public static FlowBuilder createDirectMacToMacFlow(Short tableId, int priority, MacAddress srcMac,
-            MacAddress dstMac, NodeConnectorRef dstPort) {
-        FlowBuilder macToMacFlow = new FlowBuilder() //
-                .setTableId(tableId) //
+    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)
                 .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();
@@ -63,13 +76,14 @@ public class FlowUtils {
 
         Uri outputPort = dstPort.getValue().firstKeyOf(NodeConnector.class, NodeConnectorKey.class).getId();
 
-        Action outputToControllerAction = new ActionBuilder() //
-                .setAction(new OutputActionCaseBuilder() //
-                        .setOutputAction(new OutputActionBuilder() //
-                                .setMaxLength(new Integer(0xffff)) //
-                                .setOutputNodeConnector(outputPort) //
-                                .build()) //
-                        .build()) //
+        Action outputToControllerAction = new ActionBuilder()
+                .setOrder(0)
+                .setAction(new OutputActionCaseBuilder()
+                        .setOutputAction(new OutputActionBuilder()
+                                .setMaxLength(Integer.valueOf(0xffff))
+                                .setOutputNodeConnector(outputPort)
+                                .build())
+                        .build())
                 .build();
 
         // Create an Apply Action
@@ -77,25 +91,26 @@ public class FlowUtils {
                 .build();
 
         // Wrap our Apply Action in an Instruction
-        Instruction applyActionsInstruction = new InstructionBuilder() //
-                .setInstruction(new ApplyActionsCaseBuilder()//
-                        .setApplyActions(applyActions) //
-                        .build()) //
+        Instruction applyActionsInstruction = new InstructionBuilder()
+                .setOrder(0)
+                .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(0L) //
-                .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;
@@ -107,7 +122,7 @@ public class FlowUtils {
      * @param flowId
      * @return {@link FlowBuilder} forwarding all packets to controller port
      */
-    public static FlowBuilder createFwdAllToControllerFlow(Short tableId, int priority, FlowId flowId) {
+    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));
 
@@ -115,7 +130,7 @@ public class FlowUtils {
 
         // 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);
 
@@ -143,13 +158,13 @@ public class FlowUtils {
         instructions.add(ib.build());
         isb.setInstruction(instructions);
 
-        allToCtrlFlow //
-            .setMatch(matchBuilder.build()) //
-            .setInstructions(isb.build()) //
-            .setPriority(priority) //
-            .setBufferId(0L) //
-            .setHardTimeout(0) //
-            .setIdleTimeout(0) //
+        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;