Merge "Removed duplicate declaration in pom.xml."
[openflowplugin.git] / openflowplugin-impl / src / main / java / org / opendaylight / openflowplugin / impl / util / GroupUtil.java
index d6b250e25596829de9b5c1d33eae08f46a72aa90..d572eea2340e986aeab058169b46704f1d64eeda 100644 (file)
@@ -39,6 +39,7 @@ import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
 import org.opendaylight.yangtools.yang.common.RpcError;
 import org.opendaylight.yangtools.yang.common.RpcResult;
 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.ActionType;
 
 /**
  * provides group util methods
@@ -121,44 +122,38 @@ public final class GroupUtil {
     public static <O> Function<List<RpcResult<O>>, RpcResult<List<BatchFailedGroupsOutput>>> createCumulatingFunction(
             final Iterable<? extends org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.Group> inputBatchGroups,
             final int sizeOfInputBatch) {
-        return new Function<List<RpcResult<O>>, RpcResult<List<BatchFailedGroupsOutput>>>() {
-            @Nullable
-            @Override
-            public RpcResult<List<BatchFailedGroupsOutput>> apply(@Nullable final List<RpcResult<O>> innerInput) {
-                final int sizeOfFutures = innerInput.size();
-                Preconditions.checkArgument(sizeOfFutures == sizeOfInputBatch,
-                        "wrong amount of returned futures: {} <> {}", sizeOfFutures, sizeOfInputBatch);
-
-                final List<BatchFailedGroupsOutput> batchGroups = new ArrayList<>();
-                final Iterator<? extends org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.Group>
-                        batchGroupIterator = inputBatchGroups.iterator();
-
-                Collection<RpcError> groupErrors = new ArrayList<>(sizeOfFutures);
-
-                int batchOrder = 0;
-                for (RpcResult<O> groupModOutput : innerInput) {
-                    final GroupId groupId = batchGroupIterator.next().getGroupId();
-
-                    if (!groupModOutput.isSuccessful()) {
-                        batchGroups.add(new BatchFailedGroupsOutputBuilder()
-                                .setGroupId(groupId)
-                                .setBatchOrder(batchOrder)
-                                .build());
-                        groupErrors.addAll(groupModOutput.getErrors());
-                    }
-                    batchOrder++;
-                }
+        return new CumulatingFunction<O>(inputBatchGroups, sizeOfInputBatch).invoke();
+    }
 
-                final RpcResultBuilder<List<BatchFailedGroupsOutput>> resultBuilder;
-                if (!groupErrors.isEmpty()) {
-                    resultBuilder = RpcResultBuilder.<List<BatchFailedGroupsOutput>>failed()
-                            .withRpcErrors(groupErrors).withResult(batchGroups);
-                } else {
-                    resultBuilder = SUCCESSFUL_GROUP_OUTPUT_RPC_RESULT;
-                }
-                return resultBuilder.build();
-            }
-        };
+    /*
+     * Method returns the bitmap of actions supported by each group.
+     *
+     * @param actionsSupported
+     * @return
+     */
+    public static List<Long> extractGroupActionsSupportBitmap(final List<ActionType> actionsSupported) {
+        List<Long> supportActionByGroups = new ArrayList<>();
+        for (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.ActionType supportedActions : actionsSupported) {
+            long supportActionBitmap = 0;
+            supportActionBitmap |= supportedActions.isOFPATOUTPUT() ? (1) : 0;
+            supportActionBitmap |= supportedActions.isOFPATCOPYTTLOUT() ? (1 << 11) : 0;
+            supportActionBitmap |= supportedActions.isOFPATCOPYTTLIN() ? (1 << 12) : 0;
+            supportActionBitmap |= supportedActions.isOFPATSETMPLSTTL() ? (1 << 15) : 0;
+            supportActionBitmap |= supportedActions.isOFPATDECMPLSTTL() ? (1 << 16) : 0;
+            supportActionBitmap |= supportedActions.isOFPATPUSHVLAN() ? (1 << 17) : 0;
+            supportActionBitmap |= supportedActions.isOFPATPOPVLAN() ? (1 << 18) : 0;
+            supportActionBitmap |= supportedActions.isOFPATPUSHMPLS() ? (1 << 19) : 0;
+            supportActionBitmap |= supportedActions.isOFPATPOPMPLS() ? (1 << 20) : 0;
+            supportActionBitmap |= supportedActions.isOFPATSETQUEUE() ? (1 << 21) : 0;
+            supportActionBitmap |= supportedActions.isOFPATGROUP() ? (1 << 22) : 0;
+            supportActionBitmap |= supportedActions.isOFPATSETNWTTL() ? (1 << 23) : 0;
+            supportActionBitmap |= supportedActions.isOFPATDECNWTTL() ? (1 << 24) : 0;
+            supportActionBitmap |= supportedActions.isOFPATSETFIELD() ? (1 << 25) : 0;
+            supportActionBitmap |= supportedActions.isOFPATPUSHPBB() ? (1 << 26) : 0;
+            supportActionBitmap |= supportedActions.isOFPATPOPPBB() ? (1 << 27) : 0;
+            supportActionByGroups.add(supportActionBitmap);
+        }
+        return supportActionByGroups;
     }
 
     /**
@@ -204,7 +199,7 @@ public final class GroupUtil {
      * @return batch group operation output of given type containing list of group-ids and corresponding success flag
      */
     private static <T extends BatchGroupOutputListGrouping>
-    RpcResultBuilder<T> createCumulativeRpcResult(final @Nullable RpcResult<List<BatchFailedGroupsOutput>> batchGroupsCumulativeResult,
+    RpcResultBuilder<T> createCumulativeRpcResult(@Nullable final RpcResult<List<BatchFailedGroupsOutput>> batchGroupsCumulativeResult,
                                                   final T batchOutput) {
         final RpcResultBuilder<T> resultBld;
         if (batchGroupsCumulativeResult.isSuccessful()) {
@@ -216,4 +211,55 @@ public final class GroupUtil {
         }
         return resultBld;
     }
+
+    private static class CumulatingFunction<O> {
+        private final Iterable<? extends org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.Group> inputBatchGroups;
+        private final int sizeOfInputBatch;
+
+        public CumulatingFunction(Iterable<? extends org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.Group> inputBatchGroups, int sizeOfInputBatch) {
+            this.inputBatchGroups = inputBatchGroups;
+            this.sizeOfInputBatch = sizeOfInputBatch;
+        }
+
+        public Function<List<RpcResult<O>>, RpcResult<List<BatchFailedGroupsOutput>>> invoke() {
+            return new Function<List<RpcResult<O>>, RpcResult<List<BatchFailedGroupsOutput>>>() {
+                @Nullable
+                @Override
+                public RpcResult<List<BatchFailedGroupsOutput>> apply(@Nullable final List<RpcResult<O>> innerInput) {
+                    final int sizeOfFutures = innerInput.size();
+                    Preconditions.checkArgument(sizeOfFutures == sizeOfInputBatch,
+                            "wrong amount of returned futures: {} <> {}", sizeOfFutures, sizeOfInputBatch);
+
+                    final List<BatchFailedGroupsOutput> batchGroups = new ArrayList<>();
+                    final Iterator<? extends org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.Group>
+                            batchGroupIterator = inputBatchGroups.iterator();
+
+                    Collection<RpcError> groupErrors = new ArrayList<>(sizeOfFutures);
+
+                    int batchOrder = 0;
+                    for (RpcResult<O> groupModOutput : innerInput) {
+                        final GroupId groupId = batchGroupIterator.next().getGroupId();
+
+                        if (!groupModOutput.isSuccessful()) {
+                            batchGroups.add(new BatchFailedGroupsOutputBuilder()
+                                    .setGroupId(groupId)
+                                    .setBatchOrder(batchOrder)
+                                    .build());
+                            groupErrors.addAll(groupModOutput.getErrors());
+                        }
+                        batchOrder++;
+                    }
+
+                    final RpcResultBuilder<List<BatchFailedGroupsOutput>> resultBuilder;
+                    if (!groupErrors.isEmpty()) {
+                        resultBuilder = RpcResultBuilder.<List<BatchFailedGroupsOutput>>failed()
+                                .withRpcErrors(groupErrors).withResult(batchGroups);
+                    } else {
+                        resultBuilder = SUCCESSFUL_GROUP_OUTPUT_RPC_RESULT;
+                    }
+                    return resultBuilder.build();
+                }
+            };
+        }
+    }
 }