Merge "SONAR TD - StatisticsContextImpl, StatisticsManagerImpl"
authorShuva Jyoti Kar <shuva.jyoti.kar@ericsson.com>
Mon, 15 Aug 2016 14:41:12 +0000 (14:41 +0000)
committerGerrit Code Review <gerrit@opendaylight.org>
Mon, 15 Aug 2016 14:41:12 +0000 (14:41 +0000)
80 files changed:
applications/forwardingrules-sync/src/main/java/org/opendaylight/openflowplugin/applications/frsync/impl/SimplifiedConfigListener.java
applications/forwardingrules-sync/src/main/java/org/opendaylight/openflowplugin/applications/frsync/impl/SimplifiedOperationalListener.java
applications/forwardingrules-sync/src/main/java/org/opendaylight/openflowplugin/applications/frsync/impl/SyncReactorGuardDecorator.java
applications/forwardingrules-sync/src/main/java/org/opendaylight/openflowplugin/applications/frsync/impl/SyncReactorImpl.java
applications/forwardingrules-sync/src/main/java/org/opendaylight/openflowplugin/applications/frsync/impl/clustering/DeviceMastershipManager.java
applications/forwardingrules-sync/src/main/java/org/opendaylight/openflowplugin/applications/frsync/impl/strategy/FlowForwarder.java
applications/forwardingrules-sync/src/main/java/org/opendaylight/openflowplugin/applications/frsync/impl/strategy/SyncPlanPushStrategyFlatBatchImpl.java
applications/forwardingrules-sync/src/main/java/org/opendaylight/openflowplugin/applications/frsync/util/FxChainUtil.java
applications/forwardingrules-sync/src/main/java/org/opendaylight/openflowplugin/applications/frsync/util/ModificationUtil.java
applications/forwardingrules-sync/src/main/java/org/opendaylight/openflowplugin/applications/frsync/util/PathUtil.java
applications/forwardingrules-sync/src/main/java/org/opendaylight/openflowplugin/applications/frsync/util/ReconcileUtil.java
applications/forwardingrules-sync/src/main/java/org/opendaylight/openflowplugin/applications/frsync/util/SwitchFlowId.java
applications/forwardingrules-sync/src/main/java/org/opendaylight/openflowplugin/applications/frsync/util/SyncupEntry.java
applications/forwardingrules-sync/src/test/java/org/opendaylight/openflowplugin/applications/frsync/impl/ForwardingRulesSyncProviderTest.java
applications/lldp-speaker/pom.xml
applications/lldp-speaker/src/main/java/org/opendaylight/openflowplugin/applications/lldpspeaker/LLDPSpeaker.java
applications/lldp-speaker/src/main/java/org/opendaylight/openflowplugin/applications/lldpspeaker/LLDPUtil.java
applications/lldp-speaker/src/main/java/org/opendaylight/openflowplugin/applications/lldpspeaker/NodeConnectorEventsObserver.java
applications/lldp-speaker/src/main/java/org/opendaylight/openflowplugin/applications/lldpspeaker/NodeConnectorInventoryEventTranslator.java
applications/lldp-speaker/src/main/java/org/opendaylight/openflowplugin/applications/lldpspeaker/OperationalStatusChangeService.java
applications/lldp-speaker/src/main/resources/org/opendaylight/blueprint/lldp-speaker.xml
applications/lldp-speaker/src/test/java/org/opendaylight/openflowplugin/applications/lldpspeaker/LLDPSpeakerTest.java
applications/lldp-speaker/src/test/java/org/opendaylight/openflowplugin/applications/lldpspeaker/NodeConnectorInventoryEventTranslatorTest.java
applications/lldp-speaker/src/test/java/org/opendaylight/openflowplugin/applications/lldpspeaker/TestUtils.java
applications/topology-lldp-discovery/src/main/java/org/opendaylight/openflowplugin/applications/topology/lldp/LLDPDiscoveryListener.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/common/NodeStaticReplyTranslatorUtil.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/AbstractService.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/EchoService.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/FlowCapableTransactionServiceImpl.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/FlowService.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/GroupService.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/MeterService.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/NodeConfigServiceImpl.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/PacketProcessingServiceImpl.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/RoleService.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/SalExperimenterMessageServiceImpl.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/SalFlatBatchServiceImpl.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/SalFlowServiceImpl.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/SalPortServiceImpl.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/SalRoleServiceImpl.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/SalTableServiceImpl.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/ServiceException.java [new file with mode: 0644]
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/SinglePurposeMultipartReplyTranslator.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/AggregateFlowsInTableService.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/AllFlowsInAllTablesService.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/AllFlowsInTableService.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/AllGroupsStatsService.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/AllMeterConfigStatsService.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/AllMeterStatsService.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/AllPortStatsService.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/AllQueuesAllPortsService.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/AllQueuesOnePortService.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/FlowsInTableService.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/GroupDescriptionService.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/GroupFeaturesService.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/GroupStatsService.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/MatchingFlowsInTableService.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/MeterFeaturesService.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/MeterStatsService.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/OneQueueOnePortService.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/OpendaylightFlowTableStatisticsServiceImpl.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/PortStatsService.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/compatibility/FlowStatisticsToNotificationTransformer.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/compatibility/GroupStatisticsToNotificationTransformer.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/compatibility/MeterStatisticsToNotificationTransformer.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/compatibility/NodeConnectorStatisticsToNotificationTransformer.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/compatibility/QueueStatisticsToNotificationTransformer.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/dedicated/StatisticsGatheringOnTheFlyService.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/dedicated/StatisticsGatheringService.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/AbstractDirectStatisticsService.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/util/DeviceInitializationUtils.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/util/FlatBatchUtil.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/util/FlowUtil.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/util/GroupUtil.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/util/MeterUtil.java
openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/services/SalPortServiceImplTest.java
openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/SinglePurposeMultipartReplyTranslatorTest.java
openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/util/GroupUtilTest.java
openflowplugin-it/pom.xml
openflowplugin-it/src/test/java/org/opendaylight/openflowplugin/openflow/md/it/OFPaxOptionsAssistant.java

index f4188e2926aa8767ef6111b6849d1a5cf491011a..6f86def8a6a9ef71f5a7c00edac2e730759ae36d 100644 (file)
@@ -26,7 +26,7 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 /**
- * Listens to config changes and delegates add/remove/update/barrier to {@link SyncReactor}.
+ * Listens to config changes and delegates sync entry to {@link SyncReactor}.
  */
 public class SimplifiedConfigListener extends AbstractFrmSyncListener<FlowCapableNode> {
     private static final Logger LOG = LoggerFactory.getLogger(SimplifiedConfigListener.class);
@@ -49,8 +49,8 @@ public class SimplifiedConfigListener extends AbstractFrmSyncListener<FlowCapabl
     }
 
     /**
-     * Compare cached operational with current config modification. If operational is not present
-     * skip calling Inventory RPCs.
+     * Update cache. If operational data are present, choose appropriate data and start syncup.
+     * Otherwise skip incoming change.
      * @throws InterruptedException from syncup
      */
     protected Optional<ListenableFuture<Boolean>> processNodeModification(
@@ -82,14 +82,9 @@ public class SimplifiedConfigListener extends AbstractFrmSyncListener<FlowCapabl
     }
 
     /**
-     * Add only what is missing in operational store. Config. node could be added in two situations:
-     * <ul>
-     * <li>Note very first time after restart was handled by operational listener. Syncup should
-     * calculate no delta (we don want to reconfigure switch if not necessary).</li>
-     * <li>But later the config. node could be deleted, after that config node added again. Syncup
-     * should calculate that everything needs to be added. Operational store should be empty in
-     * optimal case (but the switch could be reprogrammed by another person/system.</li>
-     * </ul>
+     * Add only what is missing on device. If node was added to config DS and it is already present
+     * in operational DS (connected) diff between current new configuration and actual configuration
+     * (seen in operational) should be calculated and sent to device.
      */
     private ListenableFuture<Boolean> onNodeAdded(final InstanceIdentifier<FlowCapableNode> nodePath,
                                                   final FlowCapableNode dataAfter,
@@ -102,7 +97,7 @@ public class SimplifiedConfigListener extends AbstractFrmSyncListener<FlowCapabl
 
     /**
      * Apply minimal changes very fast. For better performance needed just compare config
-     * after+before. Config listener should not be dependent on operational flows/groups while
+     * after+before. Config listener should not be dependent on operational flows/groups/meters while
      * updating config because operational store is highly async and it depends on another module in
      * system which is updating operational store (that components is also trying to solve
      * scale/performance issues on several layers).
@@ -117,9 +112,8 @@ public class SimplifiedConfigListener extends AbstractFrmSyncListener<FlowCapabl
     }
 
     /**
-     * Remove values that are being deleted in the config from the switch. Note, this could be
-     * probably optimized using dedicated wipe-out RPC, but it has impact on switch if it is
-     * programmed by two person/system
+     * Remove values that are being deleted in the config from the switch.
+     * Note, this could be probably optimized using dedicated wipe-out RPC.
      */
     private ListenableFuture<Boolean> onNodeDeleted(final InstanceIdentifier<FlowCapableNode> nodePath,
                                                     final FlowCapableNode dataBefore) throws InterruptedException {
index eb70f5d4931a61acb897a1799ebabefd6b8063c1..2f0fc01257e9acd04881443bc554e4ffd9b9e218 100644 (file)
@@ -40,7 +40,7 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 /**
- * Listens to operational new nodes and delegates add/remove/update/barrier to {@link SyncReactor}.
+ * Listens to operational changes and starts reconciliation through {@link SyncReactor} when necessary.
  */
 public class SimplifiedOperationalListener extends AbstractFrmSyncListener<Node> {
     private static final Logger LOG = LoggerFactory.getLogger(SimplifiedOperationalListener.class);
@@ -71,13 +71,8 @@ public class SimplifiedOperationalListener extends AbstractFrmSyncListener<Node>
     }
 
     /**
-     * This method behaves like this:
-     * <ul>
-     * <li>If node is added to operational store then reconciliation.</li>
-     * <li>Node is deleted from operational cache is removed.</li>
-     * <li>Skip this event otherwise.</li>
-     * </ul>
-     *
+     * Update cache, register for device masterhip when device connected and start reconciliation if device
+     * is registered and actual modification is consistent.Skip the event otherwise.
      * @throws InterruptedException from syncup
      */
     protected Optional<ListenableFuture<Boolean>> processNodeModification(
@@ -89,7 +84,7 @@ public class SimplifiedOperationalListener extends AbstractFrmSyncListener<Node>
             deviceMastershipManager.onDeviceConnected(nodeId);
         }
 
-        if (isRegisteredAndConsistentForReconcile(modification)) {
+        if (reconciliationRegistry.isRegistered(nodeId) && isConsistentForReconcile(modification)) {
             return reconciliation(modification);
         } else {
             return skipModification(modification);
@@ -98,7 +93,7 @@ public class SimplifiedOperationalListener extends AbstractFrmSyncListener<Node>
 
     /**
      * Remove if delete. Update only if FlowCapableNode Augmentation modified.
-     *
+     * Unregister for device mastership.
      * @param modification Datastore modification
      */
     private void updateCache(DataTreeModification<Node> modification) {
@@ -169,6 +164,13 @@ public class SimplifiedOperationalListener extends AbstractFrmSyncListener<Node>
         return false;
     }
 
+    /**
+     * If node is present in config DS diff between wanted configuration (in config DS) and actual device
+     * configuration (coming from operational) should be calculated and sent to device.
+     * @param modification from DS
+     * @return optional syncup future
+     * @throws InterruptedException from syncup
+     */
     private Optional<ListenableFuture<Boolean>> reconciliation(DataTreeModification<Node> modification) throws InterruptedException {
         final NodeId nodeId = ModificationUtil.nodeId(modification);
         final Optional<FlowCapableNode> nodeConfiguration = configDao.loadByNodeId(nodeId);
@@ -188,13 +190,8 @@ public class SimplifiedOperationalListener extends AbstractFrmSyncListener<Node>
         }
     }
 
-    private boolean isRegisteredAndConsistentForReconcile(DataTreeModification<Node> modification) {
+    private boolean isConsistentForReconcile(DataTreeModification<Node> modification) {
         final NodeId nodeId = PathUtil.digNodeId(modification.getRootPath().getRootIdentifier());
-
-        if (!reconciliationRegistry.isRegistered(nodeId)) {
-            return false;
-        }
-
         final FlowCapableStatisticsGatheringStatus gatheringStatus = modification.getRootNode().getDataAfter()
                 .getAugmentation(FlowCapableStatisticsGatheringStatus.class);
 
@@ -234,9 +231,7 @@ public class SimplifiedOperationalListener extends AbstractFrmSyncListener<Node>
         if (node == null) {
             return true;
         }
-
         final List<NodeConnector> nodeConnectors = node.getNodeConnector();
-
         return nodeConnectors == null || nodeConnectors.isEmpty();
     }
 
@@ -244,5 +239,5 @@ public class SimplifiedOperationalListener extends AbstractFrmSyncListener<Node>
     public LogicalDatastoreType dsType() {
         return LogicalDatastoreType.OPERATIONAL;
     }
-    
+
 }
index c51f0bb6e0a6df346efe2024a49cb776cfeba5f2..3f1b2716a3f743ccadfa1cad969f5c295d906205 100644 (file)
@@ -63,35 +63,7 @@ public class SyncReactorGuardDecorator implements SyncReactor {
             final ListenableFuture<Boolean> endResult =
                     delegate.syncup(flowcapableNodePath, syncupEntry);
 
-            Futures.addCallback(endResult, new FutureCallback<Boolean>() {
-                @Override
-                public void onSuccess(@Nullable final Boolean result) {
-                    if (LOG.isDebugEnabled()) {
-                        final long stampFinished = System.nanoTime();
-                        LOG.debug("syncup finished {} took:{} rpc:{} wait:{} guard:{} permits thread:{}", nodeId.getValue(),
-                                formatNanos(stampFinished - stampBeforeGuard),
-                                formatNanos(stampFinished - stampAfterGuard),
-                                formatNanos(stampAfterGuard - stampBeforeGuard),
-                                guard.availablePermits(), threadName());
-                    }
-
-                    releaseGuardForNodeId(guard);
-                }
-
-                @Override
-                public void onFailure(final Throwable t) {
-                    if (LOG.isDebugEnabled()) {
-                        final long stampFinished = System.nanoTime();
-                        LOG.warn("syncup failed {} took:{} rpc:{} wait:{} guard:{} permits thread:{}", nodeId.getValue(),
-                                formatNanos(stampFinished - stampBeforeGuard),
-                                formatNanos(stampFinished - stampAfterGuard),
-                                formatNanos(stampAfterGuard - stampBeforeGuard),
-                                guard.availablePermits(), threadName());
-                    }
-
-                    releaseGuardForNodeId(guard);
-                }
-            });
+            Futures.addCallback(endResult, createSyncupCallback(guard, stampBeforeGuard, stampAfterGuard, nodeId));
             return endResult;
         } catch (InterruptedException e) {
             releaseGuardForNodeId(guard);
@@ -99,7 +71,32 @@ public class SyncReactorGuardDecorator implements SyncReactor {
         }
     }
 
-    private String formatNanos(long nanos) {
+    private static FutureCallback<Boolean> createSyncupCallback(final Semaphore guard,
+                                                                final long stampBeforeGuard,
+                                                                final long stampAfterGuard,
+                                                                final NodeId nodeId) {
+        return new FutureCallback<Boolean>() {
+            @Override
+            public void onSuccess(@Nullable final Boolean result) {
+                if (LOG.isDebugEnabled()) {
+                    final long stampFinished = System.nanoTime();
+                    LOG.debug("syncup finished {} took:{} rpc:{} wait:{} guard:{} permits thread:{}", nodeId.getValue(),
+                            formatNanos(stampFinished - stampBeforeGuard), formatNanos(stampFinished - stampAfterGuard),
+                            formatNanos(stampAfterGuard - stampBeforeGuard), guard.availablePermits(), threadName());
+                }
+                releaseGuardForNodeId(guard);
+            }
+            @Override
+            public void onFailure(final Throwable t) {
+                final long stampFinished = System.nanoTime();
+                LOG.error("syncup failed {} took:{} rpc:{} wait:{} guard:{} permits thread:{}", nodeId.getValue(),
+                        formatNanos(stampFinished - stampBeforeGuard), formatNanos(stampFinished - stampAfterGuard),
+                        formatNanos(stampAfterGuard - stampBeforeGuard), guard.availablePermits(), threadName());
+                releaseGuardForNodeId(guard);
+            }};
+    }
+
+    private static String formatNanos(long nanos) {
         return "'" + TimeUnit.NANOSECONDS.toMillis(nanos) + " ms'";
     }
 
@@ -126,7 +123,7 @@ public class SyncReactorGuardDecorator implements SyncReactor {
      * Unlock and release guard.
      * @param guard semaphore guard which should be unlocked
      */
-    private void releaseGuardForNodeId(final Semaphore guard) {
+    private static void releaseGuardForNodeId(final Semaphore guard) {
         if (guard != null) {
             guard.release();
             LOG.trace("syncup release guard:{} thread:{}", guard, threadName());
index 5eb8860f884ebb35dcb609f414f5e77898bb4d85..7f1be0b3fde15bdd1aa2ad52c279c7437e9b9efa 100644 (file)
@@ -107,30 +107,20 @@ public class SyncReactorImpl implements SyncReactor {
                 if (input == null) {
                     return false;
                 }
-
                 if (LOG.isDebugEnabled()) {
                     final CrudCounts flowCrudCounts = counters.getFlowCrudCounts();
                     final CrudCounts meterCrudCounts = counters.getMeterCrudCounts();
                     final CrudCounts groupCrudCounts = counters.getGroupCrudCounts();
-                    LOG.debug("syncup outcome[{}] (added/updated/removed): flow={}/{}/{}, meter={}/{}/{}, group={}/{}/{}, took={} ms",
+                    LOG.debug("syncup outcome[{}] (added/updated/removed): flow={}/{}/{}, group={}/{}/{}, meter={}/{}/{}, took={} ms",
                             nodeId.getValue(),
-                            flowCrudCounts.getAdded(),
-                            flowCrudCounts.getUpdated(),
-                            flowCrudCounts.getRemoved(),
-                            meterCrudCounts.getAdded(),
-                            meterCrudCounts.getUpdated(),
-                            meterCrudCounts.getRemoved(),
-                            groupCrudCounts.getAdded(),
-                            groupCrudCounts.getUpdated(),
-                            groupCrudCounts.getRemoved(),
-                            TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - counters.getStartNano())
-                    );
+                            flowCrudCounts.getAdded(), flowCrudCounts.getUpdated(), flowCrudCounts.getRemoved(),
+                            groupCrudCounts.getAdded(), groupCrudCounts.getUpdated(), groupCrudCounts.getRemoved(),
+                            meterCrudCounts.getAdded(), meterCrudCounts.getUpdated(), meterCrudCounts.getRemoved(),
+                            TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - counters.getStartNano()));
                 }
-
                 LOG.trace("syncup errors: {}", input.getErrors());
                 return input.isSuccessful();
-            }
-        });
+            }});
     }
 
     @VisibleForTesting
index 41f736c05d8d2c199bd6192acfce006f406d7d64..06532ad3c2f821268a972c5a5d63b650dd8d41c8 100644 (file)
@@ -48,7 +48,7 @@ public class DeviceMastershipManager {
             try {
                 registration.close();
             } catch (Exception e) {
-                LOG.error("FRS cluster service close fail: {}", nodeId.getValue());
+                LOG.error("FRS cluster service close fail: {} {}", nodeId.getValue(), e);
             }
         }
         LOG.debug("FRS service unregistered for: {}", nodeId.getValue());
index ca752470fe978e4787ed0897d4a131b6ab853b88..2609d576f7c62b2ff0e72cdded3b5617307cbf9c 100644 (file)
@@ -41,6 +41,7 @@ import org.slf4j.LoggerFactory;
 public class FlowForwarder implements ForwardingRulesCommitter<Flow, AddFlowOutput, RemoveFlowOutput, UpdateFlowOutput> {
 
     private static final Logger LOG = LoggerFactory.getLogger(FlowForwarder.class);
+    private static final String TABLE_ID_MISMATCH = "tableId mismatch";
     private final SalFlowService salFlowService;
 
     public FlowForwarder(final SalFlowService salFlowService) {
@@ -67,7 +68,7 @@ public class FlowForwarder implements ForwardingRulesCommitter<Flow, AddFlowOutp
             return salFlowService.removeFlow(builder.build());
         } else {
             return RpcResultBuilder.<RemoveFlowOutput>failed()
-                    .withError(RpcError.ErrorType.APPLICATION, "tableId mismatch").buildFuture();
+                    .withError(RpcError.ErrorType.APPLICATION, TABLE_ID_MISMATCH).buildFuture();
         }
     }
 
@@ -94,7 +95,7 @@ public class FlowForwarder implements ForwardingRulesCommitter<Flow, AddFlowOutp
             output = salFlowService.updateFlow(builder.build());
         } else {
             output = RpcResultBuilder.<UpdateFlowOutput>failed()
-                    .withError(RpcError.ErrorType.APPLICATION, "tableId mismatch").buildFuture();
+                    .withError(RpcError.ErrorType.APPLICATION, TABLE_ID_MISMATCH).buildFuture();
         }
 
         return output;
@@ -117,7 +118,7 @@ public class FlowForwarder implements ForwardingRulesCommitter<Flow, AddFlowOutp
             builder.setFlowTable(new FlowTableRef(nodeIdent.child(Table.class, tableKey)));
             output = salFlowService.addFlow(builder.build());
         } else {
-            output = RpcResultBuilder.<AddFlowOutput>failed().withError(RpcError.ErrorType.APPLICATION, "tableId mismatch").buildFuture();
+            output = RpcResultBuilder.<AddFlowOutput>failed().withError(RpcError.ErrorType.APPLICATION, TABLE_ID_MISMATCH).buildFuture();
         }
         return output;
     }
index 70ce219708a1480efdca8f214dd9e51898e689f9..68e0803723c532b7e7a9a6de1f9fe51cc3225165 100644 (file)
@@ -174,17 +174,7 @@ public class SyncPlanPushStrategyFlatBatchImpl implements SyncPlanPushStrategy {
             public void onSuccess(@Nullable final RpcResult<ProcessFlatBatchOutput> result) {
                 if (!result.isSuccessful() && result.getResult() != null && !result.getResult().getBatchFailure().isEmpty()) {
                     Map<Range<Integer>, Batch> batchMap = mapBatchesToRanges(inputBatchBag, failureIndexLimit);
-
-                    for (BatchFailure batchFailure : result.getResult().getBatchFailure()) {
-                        for (Map.Entry<Range<Integer>, Batch> rangeBatchEntry : batchMap.entrySet()) {
-                            if (rangeBatchEntry.getKey().contains(batchFailure.getBatchOrder())) {
-                                // get type and decrease
-                                final BatchChoice batchChoice = rangeBatchEntry.getValue().getBatchChoice();
-                                decrementCounters(batchChoice, counters);
-                                break;
-                            }
-                        }
-                    }
+                    decrementBatchFailuresCounters(result.getResult().getBatchFailure(), batchMap, counters);
                 }
             }
 
@@ -195,6 +185,21 @@ public class SyncPlanPushStrategyFlatBatchImpl implements SyncPlanPushStrategy {
         };
     }
 
+    private static void decrementBatchFailuresCounters(final List<BatchFailure> batchFailures,
+                                                final Map<Range<Integer>, Batch> batchMap,
+                                                final SyncCrudCounters counters) {
+        for (BatchFailure batchFailure : batchFailures) {
+            for (Map.Entry<Range<Integer>, Batch> rangeBatchEntry : batchMap.entrySet()) {
+                if (rangeBatchEntry.getKey().contains(batchFailure.getBatchOrder())) {
+                    // get type and decrease
+                    final BatchChoice batchChoice = rangeBatchEntry.getValue().getBatchChoice();
+                    decrementCounters(batchChoice, counters);
+                    break;
+                }
+            }
+        }
+    }
+
     static void decrementCounters(final BatchChoice batchChoice, final SyncCrudCounters counters) {
         if (batchChoice instanceof FlatBatchAddFlowCase) {
             counters.getFlowCrudCounts().decAdded();
@@ -233,6 +238,7 @@ public class SyncPlanPushStrategyFlatBatchImpl implements SyncPlanPushStrategy {
     @VisibleForTesting
     static int assembleRemoveFlows(final List<Batch> batchBag, int batchOrder, final Map<TableKey, ItemSyncBox<Flow>> flowItemSyncTableMap) {
         // process flow remove
+        int order = batchOrder;
         if (flowItemSyncTableMap != null) {
             for (Map.Entry<TableKey, ItemSyncBox<Flow>> syncBoxEntry : flowItemSyncTableMap.entrySet()) {
                 final ItemSyncBox<Flow> flowItemSyncBox = syncBoxEntry.getValue();
@@ -251,19 +257,20 @@ public class SyncPlanPushStrategyFlatBatchImpl implements SyncPlanPushStrategy {
                             .setBatchChoice(new FlatBatchRemoveFlowCaseBuilder()
                                     .setFlatBatchRemoveFlow(flatBatchRemoveFlowBag)
                                     .build())
-                            .setBatchOrder(batchOrder)
+                            .setBatchOrder(order)
                             .build();
-                    batchOrder += itemOrder;
+                    order += itemOrder;
                     batchBag.add(batch);
                 }
             }
         }
-        return batchOrder;
+        return order;
     }
 
     @VisibleForTesting
     static int assembleAddOrUpdateGroups(final List<Batch> batchBag, int batchOrder, final List<ItemSyncBox<Group>> groupsToAddOrUpdate) {
         // process group add+update
+        int order = batchOrder;
         if (groupsToAddOrUpdate != null) {
             for (ItemSyncBox<Group> groupItemSyncBox : groupsToAddOrUpdate) {
                 if (!groupItemSyncBox.getItemsToPush().isEmpty()) {
@@ -277,9 +284,9 @@ public class SyncPlanPushStrategyFlatBatchImpl implements SyncPlanPushStrategy {
                             .setBatchChoice(new FlatBatchAddGroupCaseBuilder()
                                     .setFlatBatchAddGroup(flatBatchAddGroupBag)
                                     .build())
-                            .setBatchOrder(batchOrder)
+                            .setBatchOrder(order)
                             .build();
-                    batchOrder += itemOrder;
+                    order += itemOrder;
                     batchBag.add(batch);
                 }
 
@@ -298,19 +305,20 @@ public class SyncPlanPushStrategyFlatBatchImpl implements SyncPlanPushStrategy {
                             .setBatchChoice(new FlatBatchUpdateGroupCaseBuilder()
                                     .setFlatBatchUpdateGroup(flatBatchUpdateGroupBag)
                                     .build())
-                            .setBatchOrder(batchOrder)
+                            .setBatchOrder(order)
                             .build();
-                    batchOrder += itemOrder;
+                    order += itemOrder;
                     batchBag.add(batch);
                 }
             }
         }
-        return batchOrder;
+        return order;
     }
 
     @VisibleForTesting
     static int assembleRemoveGroups(final List<Batch> batchBag, int batchOrder, final List<ItemSyncBox<Group>> groupsToRemoveOrUpdate) {
         // process group add+update
+        int order = batchOrder;
         if (groupsToRemoveOrUpdate != null) {
             for (ItemSyncBox<Group> groupItemSyncBox : groupsToRemoveOrUpdate) {
                 if (!groupItemSyncBox.getItemsToPush().isEmpty()) {
@@ -324,19 +332,20 @@ public class SyncPlanPushStrategyFlatBatchImpl implements SyncPlanPushStrategy {
                             .setBatchChoice(new FlatBatchRemoveGroupCaseBuilder()
                                     .setFlatBatchRemoveGroup(flatBatchRemoveGroupBag)
                                     .build())
-                            .setBatchOrder(batchOrder)
+                            .setBatchOrder(order)
                             .build();
-                    batchOrder += itemOrder;
+                    order += itemOrder;
                     batchBag.add(batch);
                 }
             }
         }
-        return batchOrder;
+        return order;
     }
 
     @VisibleForTesting
     static int assembleAddOrUpdateMeters(final List<Batch> batchBag, int batchOrder, final ItemSyncBox<Meter> meterItemSyncBox) {
         // process meter add+update
+        int order = batchOrder;
         if (meterItemSyncBox != null) {
             if (!meterItemSyncBox.getItemsToPush().isEmpty()) {
                 final List<FlatBatchAddMeter> flatBatchAddMeterBag =
@@ -349,9 +358,9 @@ public class SyncPlanPushStrategyFlatBatchImpl implements SyncPlanPushStrategy {
                         .setBatchChoice(new FlatBatchAddMeterCaseBuilder()
                                 .setFlatBatchAddMeter(flatBatchAddMeterBag)
                                 .build())
-                        .setBatchOrder(batchOrder)
+                        .setBatchOrder(order)
                         .build();
-                batchOrder += itemOrder;
+                order += itemOrder;
                 batchBag.add(batch);
             }
 
@@ -370,18 +379,19 @@ public class SyncPlanPushStrategyFlatBatchImpl implements SyncPlanPushStrategy {
                         .setBatchChoice(new FlatBatchUpdateMeterCaseBuilder()
                                 .setFlatBatchUpdateMeter(flatBatchUpdateMeterBag)
                                 .build())
-                        .setBatchOrder(batchOrder)
+                        .setBatchOrder(order)
                         .build();
-                batchOrder += itemOrder;
+                order += itemOrder;
                 batchBag.add(batch);
             }
         }
-        return batchOrder;
+        return order;
     }
 
     @VisibleForTesting
     static int assembleRemoveMeters(final List<Batch> batchBag, int batchOrder, final ItemSyncBox<Meter> meterItemSyncBox) {
         // process meter remove
+        int order = batchOrder;
         if (meterItemSyncBox != null && !meterItemSyncBox.getItemsToPush().isEmpty()) {
             final List<FlatBatchRemoveMeter> flatBatchRemoveMeterBag =
                     new ArrayList<>(meterItemSyncBox.getItemsToUpdate().size());
@@ -393,17 +403,18 @@ public class SyncPlanPushStrategyFlatBatchImpl implements SyncPlanPushStrategy {
                     .setBatchChoice(new FlatBatchRemoveMeterCaseBuilder()
                             .setFlatBatchRemoveMeter(flatBatchRemoveMeterBag)
                             .build())
-                    .setBatchOrder(batchOrder)
+                    .setBatchOrder(order)
                     .build();
-            batchOrder += itemOrder;
+            order += itemOrder;
             batchBag.add(batch);
         }
-        return batchOrder;
+        return order;
     }
 
     @VisibleForTesting
     static int assembleAddOrUpdateFlows(final List<Batch> batchBag, int batchOrder, final Map<TableKey, ItemSyncBox<Flow>> flowItemSyncTableMap) {
         // process flow add+update
+        int order = batchOrder;
         if (flowItemSyncTableMap != null) {
             for (Map.Entry<TableKey, ItemSyncBox<Flow>> syncBoxEntry : flowItemSyncTableMap.entrySet()) {
                 final ItemSyncBox<Flow> flowItemSyncBox = syncBoxEntry.getValue();
@@ -422,9 +433,9 @@ public class SyncPlanPushStrategyFlatBatchImpl implements SyncPlanPushStrategy {
                             .setBatchChoice(new FlatBatchAddFlowCaseBuilder()
                                     .setFlatBatchAddFlow(flatBatchAddFlowBag)
                                     .build())
-                            .setBatchOrder(batchOrder)
+                            .setBatchOrder(order)
                             .build();
-                    batchOrder += itemOrder;
+                    order += itemOrder;
                     batchBag.add(batch);
                 }
 
@@ -444,14 +455,14 @@ public class SyncPlanPushStrategyFlatBatchImpl implements SyncPlanPushStrategy {
                             .setBatchChoice(new FlatBatchUpdateFlowCaseBuilder()
                                     .setFlatBatchUpdateFlow(flatBatchUpdateFlowBag)
                                     .build())
-                            .setBatchOrder(batchOrder)
+                            .setBatchOrder(order)
                             .build();
-                    batchOrder += itemOrder;
+                    order += itemOrder;
                     batchBag.add(batch);
                 }
             }
         }
-        return batchOrder;
+        return order;
     }
 
     public SyncPlanPushStrategyFlatBatchImpl setFlatBatchService(final SalFlatBatchService flatBatchService) {
index 903dd207f018b2de94fcf6e503d7927d7b464648..5e02d48a39d8aedbfe626282b07aea6dfc6f4d17 100644 (file)
@@ -27,6 +27,10 @@ public class FxChainUtil {
 
     private static final Logger LOG = LoggerFactory.getLogger(FxChainUtil.class);
 
+    private FxChainUtil() {
+        throw new IllegalStateException("This class should not be instantiated.");
+    }
+
 
     public static FutureCallback<RpcResult<Void>> logResultCallback(final NodeId nodeId, final String prefix) {
         return new FutureCallback<RpcResult<Void>>() {
index 1df1f7c6a43628a218d58ab5a623ea71641820d4..0eb7252725f233603d47c387285f51576f782406 100644 (file)
@@ -18,6 +18,11 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.N
  * Basic {@link DataTreeModification} related tools.
  */
 public class ModificationUtil {
+
+    private ModificationUtil() {
+        throw new IllegalStateException("This class should not be instantiated.");
+    }
+
     public static String nodeIdValue(DataTreeModification<Node> modification) {
         final NodeId nodeId = nodeId(modification);
 
index f4a91c237b8c2961d4d0acc4e724fe158c254e76..9f84a63851c3090819acc938be983f335cf8a698 100644 (file)
@@ -18,6 +18,10 @@ import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
  * Basic {@link InstanceIdentifier} related tools.
  */
 public class PathUtil {
+
+    private PathUtil() {
+        throw new IllegalStateException("This class should not be instantiated.");
+    }
     public static NodeId digNodeId(final InstanceIdentifier<?> nodeIdent) {
         return nodeIdent.firstKeyOf(Node.class, NodeKey.class).getId();
     }
index 79fd17a69774be0ca6c2587ab4009fcfd2fa83b7..a910c01957e0dc8ec57d817d3f9a7a7da105dbcb 100644 (file)
@@ -23,7 +23,6 @@ import java.util.List;
 import java.util.Map;
 import java.util.Objects;
 import java.util.Set;
-import javax.annotation.Nullable;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.GroupActionCase;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
@@ -50,41 +49,39 @@ import org.slf4j.LoggerFactory;
 /**
  * Util methods for group reconcil task (future chaining, transforms).
  */
-public class ReconcileUtil {
+public final class ReconcileUtil {
 
     private static final Logger LOG = LoggerFactory.getLogger(ReconcileUtil.class);
 
+    private ReconcileUtil() {
+        throw new IllegalStateException("This class should not be instantiated.");
+    }
+
     /**
      * @param previousItemAction description for case when the triggering future contains failure
      * @param <D>                type of rpc output (gathered in list)
      * @return single rpc result of type Void honoring all partial rpc results
      */
     public static <D> Function<List<RpcResult<D>>, RpcResult<Void>> createRpcResultCondenser(final String previousItemAction) {
-        return new Function<List<RpcResult<D>>, RpcResult<Void>>() {
-            @Nullable
-            @Override
-            public RpcResult<Void> apply(@Nullable final List<RpcResult<D>> input) {
-                final RpcResultBuilder<Void> resultSink;
-                if (input != null) {
-                    List<RpcError> errors = new ArrayList<>();
-                    for (RpcResult<D> rpcResult : input) {
-                        if (!rpcResult.isSuccessful()) {
-                            errors.addAll(rpcResult.getErrors());
-                        }
-                    }
-                    if (errors.isEmpty()) {
-                        resultSink = RpcResultBuilder.success();
-                    } else {
-                        resultSink = RpcResultBuilder.<Void>failed().withRpcErrors(errors);
+        return input -> {
+            final RpcResultBuilder<Void> resultSink;
+            if (input != null) {
+                List<RpcError> errors = new ArrayList<>();
+                for (RpcResult<D> rpcResult : input) {
+                    if (!rpcResult.isSuccessful()) {
+                        errors.addAll(rpcResult.getErrors());
                     }
+                }
+                if (errors.isEmpty()) {
+                    resultSink = RpcResultBuilder.success();
                 } else {
-                    resultSink = RpcResultBuilder.<Void>failed()
-                            .withError(RpcError.ErrorType.APPLICATION, "previous " + previousItemAction + " failed");
-
+                    resultSink = RpcResultBuilder.<Void>failed().withRpcErrors(errors);
                 }
-
-                return resultSink.build();
+            } else {
+                resultSink = RpcResultBuilder.<Void>failed()
+                        .withError(RpcError.ErrorType.APPLICATION, "previous " + previousItemAction + " failed");
             }
+            return resultSink.build();
         };
     }
 
@@ -94,27 +91,21 @@ public class ReconcileUtil {
      * @return single rpc result of type Void honoring all partial rpc results
      */
     public static <D> Function<RpcResult<D>, RpcResult<Void>> createRpcResultToVoidFunction(final String actionDescription) {
-        return new Function<RpcResult<D>, RpcResult<Void>>() {
-            @Nullable
-            @Override
-            public RpcResult<Void> apply(@Nullable final RpcResult<D> input) {
-                final RpcResultBuilder<Void> resultSink;
-                if (input != null) {
-                    List<RpcError> errors = new ArrayList<>();
-                    if (!input.isSuccessful()) {
-                        errors.addAll(input.getErrors());
-                        resultSink = RpcResultBuilder.<Void>failed().withRpcErrors(errors);
-                    } else {
-                        resultSink = RpcResultBuilder.success();
-                    }
+        return input -> {
+            final RpcResultBuilder<Void> resultSink;
+            if (input != null) {
+                List<RpcError> errors = new ArrayList<>();
+                if (!input.isSuccessful()) {
+                    errors.addAll(input.getErrors());
+                    resultSink = RpcResultBuilder.<Void>failed().withRpcErrors(errors);
                 } else {
-                    resultSink = RpcResultBuilder.<Void>failed()
-                            .withError(RpcError.ErrorType.APPLICATION, "action of " + actionDescription + " failed");
-
+                    resultSink = RpcResultBuilder.success();
                 }
-
-                return resultSink.build();
+            } else {
+                resultSink = RpcResultBuilder.<Void>failed()
+                        .withError(RpcError.ErrorType.APPLICATION, "action of " + actionDescription + " failed");
             }
+            return resultSink.build();
         };
     }
 
@@ -157,7 +148,6 @@ public class ReconcileUtil {
                                                                       final Map<Long, Group> installedGroupsArg,
                                                                       final Collection<Group> pendingGroups,
                                                                       final boolean gatherUpdates) {
-
         final Map<Long, Group> installedGroups = new HashMap<>(installedGroupsArg);
         final List<ItemSyncBox<Group>> plan = new ArrayList<>();
 
index 5a9fbbaa2d5de8048c3c7dd3110205f08b31e3bf..8ccc9b203f42be188700e95ce964115c51828666 100644 (file)
@@ -29,6 +29,26 @@ public class SwitchFlowId {
         this.match = flow.getMatch();
     }
 
+    @Override
+    public boolean equals(Object o) {
+        if (this == o) {
+            return true;
+        }
+        if (o == null || getClass() != o.getClass()) {
+            return false;
+        }
+
+        SwitchFlowId that = (SwitchFlowId) o;
+
+        if (tableId != null ? !tableId.equals(that.tableId) : that.tableId != null) {
+            return false;
+        }
+        if (priority != null ? !priority.equals(that.priority) : that.priority != null) {
+            return false;
+        }
+        return match != null ? match.equals(that.match) : that.match == null;
+    }
+
     @Override
     public int hashCode() {
         final int prime = 31;
@@ -39,30 +59,4 @@ public class SwitchFlowId {
         return result;
     }
 
-    @Override
-    public boolean equals(Object obj) {
-        if (this == obj)
-            return true;
-        if (obj == null)
-            return false;
-        if (getClass() != obj.getClass())
-            return false;
-        SwitchFlowId other = (SwitchFlowId) obj;
-        if (match == null) {
-            if (other.match != null)
-                return false;
-        } else if (!match.equals(other.match))
-            return false;
-        if (priority == null) {
-            if (other.priority != null)
-                return false;
-        } else if (!priority.equals(other.priority))
-            return false;
-        if (tableId == null) {
-            if (other.tableId != null)
-                return false;
-        } else if (!tableId.equals(other.tableId))
-            return false;
-        return true;
-    }
 }
index 151724c563181515c8159ff037c02231562d621f..290730e4cc42928c593b4e98890158369ccaf3af 100644 (file)
@@ -71,4 +71,14 @@ public class SyncupEntry {
         return dsTypeBefore == that.dsTypeBefore;
     }
 
+    @Override
+    public int hashCode() {
+        final int prime = 31;
+        int result = after != null ? after.hashCode() : 0;
+        result = prime * result + (dsTypeAfter != null ? dsTypeAfter.hashCode() : 0);
+        result = prime * result + (before != null ? before.hashCode() : 0);
+        result = prime * result + (dsTypeBefore != null ? dsTypeBefore.hashCode() : 0);
+        return result;
+    }
+
 }
index b795b2f728b73f8059ec48a185f2a90e14c6397a..a9a649462ae0654486717e4451eee885fc9e18e2 100644 (file)
@@ -7,6 +7,7 @@
  */
 package org.opendaylight.openflowplugin.applications.frsync.impl;
 
+import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
@@ -71,4 +72,10 @@ public class ForwardingRulesSyncProviderTest {
                 Matchers.<DataTreeIdentifier<FlowCapableNode>>any(),
                 Matchers.<DataTreeChangeListener<FlowCapableNode>>any());
     }
+
+    @After
+    public void tearDown() throws InterruptedException {
+        provider.close();
+    }
+
 }
\ No newline at end of file
index ec0cc97ba31d8de8d8fd5eff5c6c25c6e5e675ff..f148415351958473b91bf5781c8d1cb8df36a05c 100644 (file)
             <groupId>org.opendaylight.openflowplugin.model</groupId>
             <artifactId>model-flow-service</artifactId>
         </dependency>
+        <dependency>
+            <groupId>org.opendaylight.openflowplugin</groupId>
+            <artifactId>openflowplugin-common</artifactId>
+        </dependency>
         <dependency>
             <groupId>org.opendaylight.controller</groupId>
             <artifactId>config-api</artifactId>
index a7854072167122dd46442d1bd3dd7d3391e453f3..5c0f71fe923e4f6a72faa032998a6952da9a4b19 100644 (file)
@@ -34,24 +34,20 @@ import org.slf4j.LoggerFactory;
  * Objects of this class send LLDP frames over all flow-capable ports that can
  * be discovered through inventory.
  */
-public class LLDPSpeaker implements AutoCloseable, NodeConnectorEventsObserver,
-        Runnable {
-
-    private static final Logger LOG = LoggerFactory
-            .getLogger(LLDPSpeaker.class);
+public class LLDPSpeaker implements AutoCloseable, NodeConnectorEventsObserver, Runnable {
+    private static final Logger LOG = LoggerFactory.getLogger(LLDPSpeaker.class);
     private static final long LLDP_FLOOD_PERIOD = 5;
 
     private final PacketProcessingService packetProcessingService;
     private final ScheduledExecutorService scheduledExecutorService;
-    private final Map<InstanceIdentifier<NodeConnector>, TransmitPacketInput> nodeConnectorMap = new ConcurrentHashMap<>();
+    private final Map<InstanceIdentifier<NodeConnector>, TransmitPacketInput> nodeConnectorMap =
+            new ConcurrentHashMap<>();
     private final ScheduledFuture<?> scheduledSpeakerTask;
     private final MacAddress addressDestionation;
     private volatile OperStatus operationalStatus = OperStatus.RUN;
 
-    public LLDPSpeaker(final PacketProcessingService packetProcessingService,
-            final MacAddress addressDestionation) {
-        this(packetProcessingService, Executors
-                .newSingleThreadScheduledExecutor(), addressDestionation);
+    public LLDPSpeaker(final PacketProcessingService packetProcessingService, final MacAddress addressDestionation) {
+        this(packetProcessingService, Executors.newSingleThreadScheduledExecutor(), addressDestionation);
     }
 
     public void setOperationalStatus(final OperStatus operationalStatus) {
@@ -67,17 +63,14 @@ public class LLDPSpeaker implements AutoCloseable, NodeConnectorEventsObserver,
     }
 
     public LLDPSpeaker(final PacketProcessingService packetProcessingService,
-            final ScheduledExecutorService scheduledExecutorService,
-            final MacAddress addressDestionation) {
+                       final ScheduledExecutorService scheduledExecutorService,
+                       final MacAddress addressDestionation) {
         this.addressDestionation = addressDestionation;
         this.scheduledExecutorService = scheduledExecutorService;
         scheduledSpeakerTask = this.scheduledExecutorService
-                .scheduleAtFixedRate(this, LLDP_FLOOD_PERIOD,
-                        LLDP_FLOOD_PERIOD, TimeUnit.SECONDS);
+                .scheduleAtFixedRate(this, LLDP_FLOOD_PERIOD,LLDP_FLOOD_PERIOD, TimeUnit.SECONDS);
         this.packetProcessingService = packetProcessingService;
-        LOG.info(
-                "LLDPSpeaker started, it will send LLDP frames each {} seconds",
-                LLDP_FLOOD_PERIOD);
+        LOG.info("LLDPSpeaker started, it will send LLDP frames each {} seconds", LLDP_FLOOD_PERIOD);
     }
 
     /**
@@ -97,17 +90,11 @@ public class LLDPSpeaker implements AutoCloseable, NodeConnectorEventsObserver,
     @Override
     public void run() {
         if (OperStatus.RUN.equals(operationalStatus)) {
-            LOG.debug("Sending LLDP frames to {} ports...", nodeConnectorMap
-                    .keySet().size());
-
-            for (InstanceIdentifier<NodeConnector> nodeConnectorInstanceId : nodeConnectorMap
-                    .keySet()) {
-                NodeConnectorId nodeConnectorId = InstanceIdentifier.keyOf(
-                        nodeConnectorInstanceId).getId();
-                LOG.trace("Sending LLDP through port {}",
-                        nodeConnectorId.getValue());
-                packetProcessingService.transmitPacket(nodeConnectorMap
-                        .get(nodeConnectorInstanceId));
+            LOG.debug("Sending LLDP frames to {} ports...", nodeConnectorMap.keySet().size());
+            for (InstanceIdentifier<NodeConnector> nodeConnectorInstanceId : nodeConnectorMap.keySet()) {
+                NodeConnectorId nodeConnectorId = InstanceIdentifier.keyOf(nodeConnectorInstanceId).getId();
+                LOG.trace("Sending LLDP through port {}", nodeConnectorId.getValue());
+                packetProcessingService.transmitPacket(nodeConnectorMap.get(nodeConnectorInstanceId));
             }
         }
     }
@@ -116,11 +103,9 @@ public class LLDPSpeaker implements AutoCloseable, NodeConnectorEventsObserver,
      * {@inheritDoc}
      */
     @Override
-    public void nodeConnectorAdded(
-            final InstanceIdentifier<NodeConnector> nodeConnectorInstanceId,
-            final FlowCapableNodeConnector flowConnector) {
-        NodeConnectorId nodeConnectorId = InstanceIdentifier.keyOf(
-                nodeConnectorInstanceId).getId();
+    public void nodeConnectorAdded(final InstanceIdentifier<NodeConnector> nodeConnectorInstanceId,
+                                   final FlowCapableNodeConnector flowConnector) {
+        NodeConnectorId nodeConnectorId = InstanceIdentifier.keyOf(nodeConnectorInstanceId).getId();
 
         // nodeConnectorAdded can be called even if we already sending LLDP
         // frames to
@@ -133,16 +118,14 @@ public class LLDPSpeaker implements AutoCloseable, NodeConnectorEventsObserver,
         }
 
         // Prepare to build LLDP payload
-        InstanceIdentifier<Node> nodeInstanceId = nodeConnectorInstanceId
-                .firstIdentifierOf(Node.class);
+        InstanceIdentifier<Node> nodeInstanceId = nodeConnectorInstanceId.firstIdentifierOf(Node.class);
         NodeId nodeId = InstanceIdentifier.keyOf(nodeInstanceId).getId();
         MacAddress srcMacAddress = flowConnector.getHardwareAddress();
         Long outputPortNo = flowConnector.getPortNumber().getUint32();
 
         // No need to send LLDP frames on local ports
         if (outputPortNo == null) {
-            LOG.trace("Port {} is local, not sending LLDP frames through it",
-                    nodeConnectorId.getValue());
+            LOG.trace("Port {} is local, not sending LLDP frames through it", nodeConnectorId.getValue());
             return;
         }
 
@@ -150,16 +133,14 @@ public class LLDPSpeaker implements AutoCloseable, NodeConnectorEventsObserver,
         TransmitPacketInput packet = new TransmitPacketInputBuilder()
                 .setEgress(new NodeConnectorRef(nodeConnectorInstanceId))
                 .setNode(new NodeRef(nodeInstanceId))
-                .setPayload(
-                        LLDPUtil.buildLldpFrame(nodeId, nodeConnectorId,
-                                srcMacAddress, outputPortNo,
-                                addressDestionation)).build();
+                .setPayload(LLDPUtil
+                        .buildLldpFrame(nodeId, nodeConnectorId, srcMacAddress, outputPortNo, addressDestionation))
+                .build();
 
         // Save packet to node connector id -> packet map to transmit it every 5
         // seconds
         nodeConnectorMap.put(nodeConnectorInstanceId, packet);
-        LOG.trace("Port {} added to LLDPSpeaker.nodeConnectorMap",
-                nodeConnectorId.getValue());
+        LOG.trace("Port {} added to LLDPSpeaker.nodeConnectorMap", nodeConnectorId.getValue());
 
         // Transmit packet for first time immediately
         packetProcessingService.transmitPacket(packet);
@@ -169,12 +150,10 @@ public class LLDPSpeaker implements AutoCloseable, NodeConnectorEventsObserver,
      * {@inheritDoc}
      */
     @Override
-    public void nodeConnectorRemoved(
-            final InstanceIdentifier<NodeConnector> nodeConnectorInstanceId) {
+    public void nodeConnectorRemoved(final InstanceIdentifier<NodeConnector> nodeConnectorInstanceId) {
         nodeConnectorMap.remove(nodeConnectorInstanceId);
-        NodeConnectorId nodeConnectorId = InstanceIdentifier.keyOf(
-                nodeConnectorInstanceId).getId();
-        LOG.trace("Port {} removed from LLDPSpeaker.nodeConnectorMap",
-                nodeConnectorId.getValue());
+        NodeConnectorId nodeConnectorId = InstanceIdentifier.keyOf(nodeConnectorInstanceId).getId();
+        LOG.trace("Port {} removed from LLDPSpeaker.nodeConnectorMap", nodeConnectorId.getValue());
     }
+
 }
index af7703ea6376772cabf96b9bdcef5226449b0518..163d1c922a99c29d9f83c569486400db46909edd 100644 (file)
@@ -10,6 +10,7 @@ package org.opendaylight.openflowplugin.applications.lldpspeaker;
 
 import static org.opendaylight.controller.liblldp.LLDPTLV.CUSTOM_TLV_SUB_TYPE_CUSTOM_SEC;
 import static org.opendaylight.openflowplugin.applications.topology.lldp.utils.LLDPDiscoveryUtils.getValueForLLDPPacketIntegrityEnsuring;
+
 import java.math.BigInteger;
 import java.security.NoSuchAlgorithmException;
 import org.apache.commons.lang3.StringUtils;
@@ -33,19 +34,21 @@ public final class LLDPUtil {
     private static final String OF_URI_PREFIX = "openflow:";
 
     static byte[] buildLldpFrame(final NodeId nodeId,
-            final NodeConnectorId nodeConnectorId, final MacAddress src, final Long outPortNo,
-            final MacAddress destinationAddress) {
+                                 final NodeConnectorId nodeConnectorId,
+                                 final MacAddress src,
+                                 final Long outPortNo,
+                                 final MacAddress destinationAddress) {
         // Create discovery pkt
         LLDP discoveryPkt = new LLDP();
 
         // Create LLDP ChassisID TLV
         BigInteger dataPathId = dataPathIdFromNodeId(nodeId);
-        byte[] cidValue = LLDPTLV
-                .createChassisIDTLVValue(colonize(bigIntegerToPaddedHex(dataPathId)));
+        byte[] cidValue = LLDPTLV.createChassisIDTLVValue(colonize(bigIntegerToPaddedHex(dataPathId)));
         LLDPTLV chassisIdTlv = new LLDPTLV();
         chassisIdTlv.setType(LLDPTLV.TLVType.ChassisID.getValue());
         chassisIdTlv.setType(LLDPTLV.TLVType.ChassisID.getValue())
-                .setLength((short) cidValue.length).setValue(cidValue);
+                    .setLength((short) cidValue.length)
+                    .setValue(cidValue);
         discoveryPkt.setChassisId(chassisIdTlv);
 
         // Create LLDP PortID TL
@@ -53,15 +56,15 @@ public final class LLDPUtil {
         byte[] pidValue = LLDPTLV.createPortIDTLVValue(hexString);
         LLDPTLV portIdTlv = new LLDPTLV();
         portIdTlv.setType(LLDPTLV.TLVType.PortID.getValue())
-                .setLength((short) pidValue.length).setValue(pidValue);
+                 .setLength((short) pidValue.length)
+                 .setValue(pidValue);
         portIdTlv.setType(LLDPTLV.TLVType.PortID.getValue());
         discoveryPkt.setPortId(portIdTlv);
 
         // Create LLDP TTL TLV
         byte[] ttl = new byte[] { (byte) 0x13, (byte) 0x37 };
         LLDPTLV ttlTlv = new LLDPTLV();
-        ttlTlv.setType(LLDPTLV.TLVType.TTL.getValue())
-                .setLength((short) ttl.length).setValue(ttl);
+        ttlTlv.setType(LLDPTLV.TLVType.TTL.getValue()).setLength((short) ttl.length).setValue(ttl);
         discoveryPkt.setTtl(ttlTlv);
 
         // Create LLDP SystemName TLV
@@ -69,15 +72,16 @@ public final class LLDPUtil {
         LLDPTLV systemNameTlv = new LLDPTLV();
         systemNameTlv.setType(LLDPTLV.TLVType.SystemName.getValue());
         systemNameTlv.setType(LLDPTLV.TLVType.SystemName.getValue())
-                .setLength((short) snValue.length).setValue(snValue);
+                     .setLength((short) snValue.length)
+                     .setValue(snValue);
         discoveryPkt.setSystemNameId(systemNameTlv);
 
         // Create LLDP Custom TLV
-        byte[] customValue = LLDPTLV.createCustomTLVValue(nodeConnectorId
-                .getValue());
+        byte[] customValue = LLDPTLV.createCustomTLVValue(nodeConnectorId.getValue());
         LLDPTLV customTlv = new LLDPTLV();
         customTlv.setType(LLDPTLV.TLVType.Custom.getValue())
-                .setLength((short) customValue.length).setValue(customValue);
+                 .setLength((short) customValue.length)
+                 .setValue(customValue);
         discoveryPkt.addCustomTLV(customTlv);
 
         //Create LLDP CustomSec TLV
@@ -87,8 +91,8 @@ public final class LLDPUtil {
             byte[] customSecValue = LLDPTLV.createCustomTLVValue(CUSTOM_TLV_SUB_TYPE_CUSTOM_SEC, pureValue);
             LLDPTLV customSecTlv = new LLDPTLV();
             customSecTlv.setType(LLDPTLV.TLVType.Custom.getValue())
-            .setLength((short)customSecValue.length)
-            .setValue(customSecValue);
+                        .setLength((short)customSecValue.length)
+                        .setValue(customSecValue);
             discoveryPkt.addCustomTLV(customSecTlv);
         } catch (NoSuchAlgorithmException e1) {
             LOG.info("LLDP extra authenticator creation failed: {}", e1.getMessage());
@@ -100,13 +104,12 @@ public final class LLDPUtil {
         byte[] sourceMac = HexEncode.bytesFromHexString(src.getValue());
         Ethernet ethPkt = new Ethernet();
         ethPkt.setSourceMACAddress(sourceMac)
-                .setEtherType(EtherTypes.LLDP.shortValue())
-                .setPayload(discoveryPkt);
+              .setEtherType(EtherTypes.LLDP.shortValue())
+              .setPayload(discoveryPkt);
         if (destinationAddress == null) {
             ethPkt.setDestinationMACAddress(LLDP.LLDPMulticastMac);
         } else {
-            ethPkt.setDestinationMACAddress(HexEncode
-                    .bytesFromHexString(destinationAddress.getValue()));
+            ethPkt.setDestinationMACAddress(HexEncode.bytesFromHexString(destinationAddress.getValue()));
         }
 
         try {
@@ -132,9 +135,9 @@ public final class LLDPUtil {
     }
 
     static byte[] buildLldpFrame(final NodeId nodeId,
-            final NodeConnectorId nodeConnectorId, final MacAddress srcMacAddress,
-            final Long outputPortNo) {
-        return buildLldpFrame(nodeId, nodeConnectorId, srcMacAddress,
-                outputPortNo, null);
+                                 final NodeConnectorId nodeConnectorId,
+                                 final MacAddress srcMacAddress,
+                                 final Long outputPortNo) {
+        return buildLldpFrame(nodeId, nodeConnectorId, srcMacAddress, outputPortNo, null);
     }
 }
index 490cf6ad2800cd9113fd13cf7f6adcee6161416c..665f36dcd2ff9132e0021f73ae927e2fe22b60b1 100644 (file)
@@ -25,7 +25,7 @@ public interface NodeConnectorEventsObserver {
      * @param nodeConnectorInstanceId Object that uniquely identify added node connector
      * @param flowConnector object containing almost all of details about node connector
      */
-    public void nodeConnectorAdded(InstanceIdentifier<NodeConnector> nodeConnectorInstanceId,
+    void nodeConnectorAdded(InstanceIdentifier<NodeConnector> nodeConnectorInstanceId,
                                    FlowCapableNodeConnector flowConnector);
 
     /**
@@ -34,5 +34,5 @@ public interface NodeConnectorEventsObserver {
      * the same removal event.
      * @param nodeConnectorInstanceId Object that uniquely identify added node connector
      */
-    public void nodeConnectorRemoved(InstanceIdentifier<NodeConnector> nodeConnectorInstanceId);
+    void nodeConnectorRemoved(InstanceIdentifier<NodeConnector> nodeConnectorInstanceId);
 }
index 71b3b3e6ce7c6c909e238e7b6fb77c16397aaa76..835dc97e5140ed0628cd3af2040db8b1b2bf73ad 100644 (file)
@@ -8,22 +8,25 @@
 
 package org.opendaylight.openflowplugin.applications.lldpspeaker;
 
+import com.google.common.collect.ImmutableSet;
 import com.google.common.collect.Iterables;
-
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNodeConnectorBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.flow.capable.port.State;
+import java.util.Collection;
 import java.util.HashMap;
-import com.google.common.collect.ImmutableSet;
 import java.util.Map;
 import java.util.Set;
+import java.util.concurrent.Callable;
+import javax.annotation.Nonnull;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
-import org.opendaylight.controller.md.sal.binding.api.DataChangeListener;
-import org.opendaylight.controller.md.sal.common.api.data.AsyncDataBroker;
-import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent;
+import org.opendaylight.controller.md.sal.binding.api.DataTreeChangeListener;
+import org.opendaylight.controller.md.sal.binding.api.DataTreeIdentifier;
+import org.opendaylight.controller.md.sal.binding.api.DataTreeModification;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.openflowplugin.common.wait.SimpleTaskRetryLooper;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNodeConnector;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNodeConnectorBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.PortConfig;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.PortState;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.flow.capable.port.State;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnector;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
@@ -33,16 +36,14 @@ import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-
 /**
  * NodeConnectorInventoryEventTranslator is listening for changes in inventory operational DOM tree
  * and update LLDPSpeaker and topology.
  */
-public class NodeConnectorInventoryEventTranslator implements DataChangeListener, AutoCloseable {
-    /**
-     *
-     */
-    private static final InstanceIdentifier<State> II_TO_STATE 
+public class NodeConnectorInventoryEventTranslator<T extends DataObject>
+        implements DataTreeChangeListener<T>, AutoCloseable {
+
+    private static final InstanceIdentifier<State> II_TO_STATE
         = InstanceIdentifier.builder(Nodes.class)
             .child(Node.class)
             .child(NodeConnector.class)
@@ -57,111 +58,141 @@ public class NodeConnectorInventoryEventTranslator implements DataChangeListener
             .augmentation(FlowCapableNodeConnector.class)
             .build();
 
+    private static final long STARTUP_LOOP_TICK = 500L;
+    private static final int STARTUP_LOOP_MAX_RETRIES = 8;
     private static final Logger LOG = LoggerFactory.getLogger(NodeConnectorInventoryEventTranslator.class);
 
-    private final ListenerRegistration<DataChangeListener> dataChangeListenerRegistration;
-    private final ListenerRegistration<DataChangeListener> listenerOnPortStateRegistration;
+    private final ListenerRegistration<DataTreeChangeListener> dataChangeListenerRegistration;
+    private final ListenerRegistration<DataTreeChangeListener> listenerOnPortStateRegistration;
     private final Set<NodeConnectorEventsObserver> observers;
     private final Map<InstanceIdentifier<?>,FlowCapableNodeConnector> iiToDownFlowCapableNodeConnectors = new HashMap<>();
 
     public NodeConnectorInventoryEventTranslator(DataBroker dataBroker, NodeConnectorEventsObserver... observers) {
         this.observers = ImmutableSet.copyOf(observers);
-        dataChangeListenerRegistration = dataBroker.registerDataChangeListener(
-                LogicalDatastoreType.OPERATIONAL,
-                II_TO_FLOW_CAPABLE_NODE_CONNECTOR,
-                this, AsyncDataBroker.DataChangeScope.BASE);
-        listenerOnPortStateRegistration = dataBroker.registerDataChangeListener(
-                LogicalDatastoreType.OPERATIONAL,
-                II_TO_STATE,
-                this, AsyncDataBroker.DataChangeScope.SUBTREE);
+        final DataTreeIdentifier<T> dtiToNodeConnector =
+                new DataTreeIdentifier(LogicalDatastoreType.OPERATIONAL, II_TO_FLOW_CAPABLE_NODE_CONNECTOR);
+        final DataTreeIdentifier<T> dtiToNodeConnectorState =
+                new DataTreeIdentifier(LogicalDatastoreType.OPERATIONAL, II_TO_STATE);
+        final SimpleTaskRetryLooper looper = new SimpleTaskRetryLooper(STARTUP_LOOP_TICK, STARTUP_LOOP_MAX_RETRIES);
+        try {
+            dataChangeListenerRegistration = looper.loopUntilNoException(new Callable<ListenerRegistration<DataTreeChangeListener>>() {
+                @Override
+                public ListenerRegistration<DataTreeChangeListener> call() throws Exception {
+                    return dataBroker.registerDataTreeChangeListener(dtiToNodeConnector, NodeConnectorInventoryEventTranslator.this);
+                }
+            });
+            listenerOnPortStateRegistration = looper.loopUntilNoException(new Callable<ListenerRegistration<DataTreeChangeListener>>() {
+                @Override
+                public ListenerRegistration<DataTreeChangeListener> call() throws Exception {
+                    return dataBroker.registerDataTreeChangeListener(dtiToNodeConnectorState, NodeConnectorInventoryEventTranslator.this);
+                }
+            });
+        } catch (Exception e) {
+            LOG.error("DataTreeChangeListeners registration failed: {}", e);
+            throw new IllegalStateException("NodeConnectorInventoryEventTranslator startup failed!", e);
+        }
+        LOG.info("NodeConnectorInventoryEventTranslator has started.");
     }
 
     @Override
     public void close() {
-        dataChangeListenerRegistration.close();
-        listenerOnPortStateRegistration.close();
+        if (dataChangeListenerRegistration != null) {
+            dataChangeListenerRegistration.close();
+        }
+        if (listenerOnPortStateRegistration != null) {
+            listenerOnPortStateRegistration.close();
+        }
     }
 
     @Override
-    public void onDataChanged(AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> change) {
-        LOG.trace("Node connectors in inventory changed: {} created, {} updated, {} removed",
-                change.getCreatedData().size(), change.getUpdatedData().size(), change.getRemovedPaths().size());
-
-        // Iterate over created node connectors
-        for (Map.Entry<InstanceIdentifier<?>, DataObject> entry : change.getCreatedData().entrySet()) {
-            InstanceIdentifier<NodeConnector> nodeConnectorInstanceId =
-                    entry.getKey().firstIdentifierOf(NodeConnector.class);
-            if (compareIITail(entry.getKey(),II_TO_FLOW_CAPABLE_NODE_CONNECTOR)) {
-                FlowCapableNodeConnector flowConnector = (FlowCapableNodeConnector) entry.getValue();
-                if (!isPortDown(flowConnector)) {
-                    notifyNodeConnectorAppeared(nodeConnectorInstanceId, flowConnector);
-                } else {
-                    iiToDownFlowCapableNodeConnectors.put(nodeConnectorInstanceId, flowConnector);
-                }
+    public void onDataTreeChanged(@Nonnull Collection<DataTreeModification<T>> modifications) {
+        for(DataTreeModification modification : modifications) {
+            LOG.trace("Node connectors in inventory changed -> {}", modification.getRootNode().getModificationType());
+            switch (modification.getRootNode().getModificationType()) {
+                case WRITE:
+                    processAddedConnector(modification);
+                    break;
+                case SUBTREE_MODIFIED:
+                    processUpdatedConnector(modification);
+                    break;
+                case DELETE:
+                    processRemovedConnector(modification);
+                    break;
+                default:
+                    throw new IllegalArgumentException("Unhandled modification type: {}" +
+                            modification.getRootNode().getModificationType());
             }
         }
+    }
 
-        // Iterate over updated node connectors (port down state may change)
-        for (Map.Entry<InstanceIdentifier<?>, DataObject> entry : change.getUpdatedData().entrySet()) {
-            InstanceIdentifier<NodeConnector> nodeConnectorInstanceId =
-                    entry.getKey().firstIdentifierOf(NodeConnector.class);
-            if (compareIITail(entry.getKey(),II_TO_FLOW_CAPABLE_NODE_CONNECTOR)) {
-                FlowCapableNodeConnector flowConnector = (FlowCapableNodeConnector) entry.getValue();
-                if (isPortDown(flowConnector)) {
-                    notifyNodeConnectorDisappeared(nodeConnectorInstanceId);
-                } else {
-                    notifyNodeConnectorAppeared(nodeConnectorInstanceId, flowConnector);
-                }
-            } else if (compareIITail(entry.getKey(),II_TO_STATE)) {
-                FlowCapableNodeConnector flowNodeConnector = iiToDownFlowCapableNodeConnectors.get(nodeConnectorInstanceId);
-                if (flowNodeConnector != null) {
-                    State state = (State)entry.getValue();
-                    if (!state.isLinkDown()) {
-                        FlowCapableNodeConnectorBuilder flowCapableNodeConnectorBuilder = new FlowCapableNodeConnectorBuilder(flowNodeConnector);
-                        flowCapableNodeConnectorBuilder.setState(state);
-                        notifyNodeConnectorAppeared(nodeConnectorInstanceId, flowCapableNodeConnectorBuilder.build());
-                        iiToDownFlowCapableNodeConnectors.remove(nodeConnectorInstanceId);
-                    }
-                }
+    private void processAddedConnector(final DataTreeModification<T> modification) {
+        final InstanceIdentifier<T> identifier = modification.getRootPath().getRootIdentifier();
+        InstanceIdentifier<NodeConnector> nodeConnectorInstanceId =identifier.firstIdentifierOf(NodeConnector.class);
+        if (compareIITail(identifier, II_TO_FLOW_CAPABLE_NODE_CONNECTOR)) {
+            FlowCapableNodeConnector flowConnector = (FlowCapableNodeConnector) modification.getRootNode().getDataAfter();
+            if (!isPortDown(flowConnector)) {
+                notifyNodeConnectorAppeared(nodeConnectorInstanceId, flowConnector);
+            } else {
+                iiToDownFlowCapableNodeConnectors.put(nodeConnectorInstanceId, flowConnector);
             }
         }
+    }
 
-        // Iterate over removed node connectors
-        for (InstanceIdentifier<?> removed : change.getRemovedPaths()) {
-            if (compareIITail(removed,II_TO_FLOW_CAPABLE_NODE_CONNECTOR)) {
-                InstanceIdentifier<NodeConnector> nodeConnectorInstanceId = removed.firstIdentifierOf(NodeConnector.class);
+    private void processUpdatedConnector(final DataTreeModification<T> modification) {
+        final InstanceIdentifier<T> identifier = modification.getRootPath().getRootIdentifier();
+        InstanceIdentifier<NodeConnector> nodeConnectorInstanceId = identifier.firstIdentifierOf(NodeConnector.class);
+        if (compareIITail(identifier, II_TO_FLOW_CAPABLE_NODE_CONNECTOR)) {
+            FlowCapableNodeConnector flowConnector = (FlowCapableNodeConnector) modification.getRootNode().getDataAfter();
+            if (isPortDown(flowConnector)) {
                 notifyNodeConnectorDisappeared(nodeConnectorInstanceId);
+            } else {
+                notifyNodeConnectorAppeared(nodeConnectorInstanceId, flowConnector);
             }
+        } else if (compareIITail(identifier, II_TO_STATE)) {
+            FlowCapableNodeConnector flowNodeConnector = iiToDownFlowCapableNodeConnectors.get(nodeConnectorInstanceId);
+            if (flowNodeConnector != null) {
+                State state = (State) modification.getRootNode().getDataAfter();
+                if (!state.isLinkDown()) {
+                    FlowCapableNodeConnectorBuilder flowCapableNodeConnectorBuilder =
+                            new FlowCapableNodeConnectorBuilder(flowNodeConnector);
+                    flowCapableNodeConnectorBuilder.setState(state);
+                    notifyNodeConnectorAppeared(nodeConnectorInstanceId, flowCapableNodeConnectorBuilder.build());
+                    iiToDownFlowCapableNodeConnectors.remove(nodeConnectorInstanceId);
+                }
+            }
+        }
+    }
+
+    private void processRemovedConnector(final DataTreeModification<T> modification) {
+        final InstanceIdentifier<T> identifier = modification.getRootPath().getRootIdentifier();
+        if (compareIITail(identifier, II_TO_FLOW_CAPABLE_NODE_CONNECTOR)) {
+            InstanceIdentifier<NodeConnector> nodeConnectorInstanceId = identifier.firstIdentifierOf(NodeConnector.class);
+            notifyNodeConnectorDisappeared(nodeConnectorInstanceId);
         }
     }
 
-    /**
-     * @param key
-     * @param iiToFlowCapableNodeConnector
-     * @return
-     */
-    private boolean compareIITail(InstanceIdentifier<?> ii1,
-            InstanceIdentifier<?> ii2) {
+    private boolean compareIITail(final InstanceIdentifier<?> ii1, final InstanceIdentifier<?> ii2) {
         return Iterables.getLast(ii1.getPathArguments()).equals(Iterables.getLast(ii2.getPathArguments()));
     }
 
-    private static boolean isPortDown(FlowCapableNodeConnector flowCapableNodeConnector) {
+    private static boolean isPortDown(final FlowCapableNodeConnector flowCapableNodeConnector) {
         PortState portState = flowCapableNodeConnector.getState();
         PortConfig portConfig = flowCapableNodeConnector.getConfiguration();
-        return portState != null && portState.isLinkDown() ||
-                portConfig != null && portConfig.isPORTDOWN();
+        return portState != null && portState.isLinkDown()
+                || portConfig != null && portConfig.isPORTDOWN();
     }
 
-    private void notifyNodeConnectorAppeared(InstanceIdentifier<NodeConnector> nodeConnectorInstanceId,
-                                             FlowCapableNodeConnector flowConnector) {
+    private void notifyNodeConnectorAppeared(final InstanceIdentifier<NodeConnector> nodeConnectorInstanceId,
+                                             final FlowCapableNodeConnector flowConnector) {
         for (NodeConnectorEventsObserver observer : observers) {
             observer.nodeConnectorAdded(nodeConnectorInstanceId, flowConnector);
         }
     }
 
-    private void notifyNodeConnectorDisappeared(InstanceIdentifier<NodeConnector> nodeConnectorInstanceId) {
+    private void notifyNodeConnectorDisappeared(final InstanceIdentifier<NodeConnector> nodeConnectorInstanceId) {
         for (NodeConnectorEventsObserver observer : observers) {
             observer.nodeConnectorRemoved(nodeConnectorInstanceId);
         }
     }
+
 }
index f1bfd0be431f72f88f17b8da78a5e12ec3beb535..b322dbcbe3cbd7dc01bc6a1c53e4ea0637ba6c4a 100644 (file)
@@ -17,9 +17,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.openflow
 import org.opendaylight.yangtools.yang.common.RpcResult;
 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
 
-/**
- * Created by Martin Bobak mbobak@cisco.com on 11/20/14.
- */
 public class OperationalStatusChangeService implements LldpSpeakerService {
 
     private final LLDPSpeaker speakerInstance;
index 98fd805b4c97e5b439a81d05ce0c3ef63cc76b0b..ca8fa54dd97aae6a98ecf0fbb8c6045b31f63c14 100644 (file)
@@ -1,7 +1,7 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
            xmlns:odl="http://opendaylight.org/xmlns/blueprint/v1.0.0"
-        odl:use-default-for-reference-types="true">
+           odl:use-default-for-reference-types="true">
 
   <reference id="dataBroker" interface="org.opendaylight.controller.md.sal.binding.api.DataBroker"/>
 
index e02784f89ac710ba931a1fc75386148d791f1246..cd77668eac4caf326a5cf53d16851c64d11c714b 100644 (file)
@@ -19,7 +19,6 @@ import static org.mockito.Mockito.when;
 import java.util.concurrent.ScheduledExecutorService;
 import java.util.concurrent.ScheduledFuture;
 import java.util.concurrent.TimeUnit;
-
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
@@ -41,13 +40,13 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.openflow
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 
 /**
- * Tests for @{LLDPSpeaker} class.
+ * Tests for {@link LLDPSpeaker}.
  */
 @RunWith(MockitoJUnitRunner.class)
 public class LLDPSpeakerTest {
-    static InstanceIdentifier<NodeConnector> id;
-    static FlowCapableNodeConnector fcnc;
-    static TransmitPacketInput packet;
+    private static final InstanceIdentifier<NodeConnector> id;
+    private static final FlowCapableNodeConnector fcnc;
+    private static final TransmitPacketInput packet;
 
     static {
         MacAddress mac = new MacAddress("01:23:45:67:89:AB");
@@ -62,17 +61,16 @@ public class LLDPSpeakerTest {
     }
 
     @Mock
-    PacketProcessingService packetProcessingService;
+    private PacketProcessingService packetProcessingService;
     @Mock
-    ScheduledExecutorService scheduledExecutorService;
+    private ScheduledExecutorService scheduledExecutorService;
     @Mock
-    ScheduledFuture scheduledSpeakerTask;
+    private ScheduledFuture scheduledSpeakerTask;
 
-    MacAddress destinationMACAddress = null;
-    LLDPSpeaker lldpSpeaker;
+    private final MacAddress destinationMACAddress = null;
+    private LLDPSpeaker lldpSpeaker;
 
     @Before
-    @SuppressWarnings("unchecked")
     public void setUp() {
         when(
                 scheduledExecutorService.scheduleAtFixedRate(
@@ -143,7 +141,7 @@ public class LLDPSpeakerTest {
     }
 
     /**
-     * Test that when @{LLDPSpeaker#nodeConnectorAdded} is called multiple times
+     * Test that when {@link LLDPSpeaker#nodeConnectorAdded} is called multiple times
      * with same arguments, only the first one have effect.
      */
     @Test
@@ -161,12 +159,9 @@ public class LLDPSpeakerTest {
 
     /**
      * Test that lldpSpeaker cancels periodic LLDP flood task and stops
-     * 
-     * @{ScheduledExecutorService .
-     * @throws Exception
      */
     @Test
-    public void testCleanup() throws Exception {
+    public void testCleanup() {
         lldpSpeaker.close();
         verify(scheduledSpeakerTask, times(1)).cancel(true);
         verify(scheduledExecutorService, times(1)).shutdown();
index 3426d29fcccdc1a4bfb6b147cf2dbb5aa830bdb5..9ee90e653aa3184be59bd1b186c62c6ccce156ac 100644 (file)
@@ -8,68 +8,63 @@
 
 package org.opendaylight.openflowplugin.applications.lldpspeaker;
 
-import static org.mockito.Mockito.*;
-
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Set;
-import org.junit.*;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.verifyZeroInteractions;
+import static org.mockito.Mockito.when;
+import static org.opendaylight.controller.md.sal.binding.api.DataObjectModification.ModificationType.DELETE;
+import static org.opendaylight.controller.md.sal.binding.api.DataObjectModification.ModificationType.SUBTREE_MODIFIED;
+import static org.opendaylight.controller.md.sal.binding.api.DataObjectModification.ModificationType.WRITE;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import org.junit.Before;
+import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.mockito.Mock;
 import org.mockito.runners.MockitoJUnitRunner;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
-import org.opendaylight.controller.md.sal.binding.api.DataChangeListener;
-import org.opendaylight.controller.md.sal.common.api.data.AsyncDataBroker;
-import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent;
+import org.opendaylight.controller.md.sal.binding.api.DataObjectModification;
+import org.opendaylight.controller.md.sal.binding.api.DataObjectModification.ModificationType;
+import org.opendaylight.controller.md.sal.binding.api.DataTreeIdentifier;
+import org.opendaylight.controller.md.sal.binding.api.DataTreeModification;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNodeConnector;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnector;
-import org.opendaylight.yangtools.concepts.ListenerRegistration;
 import org.opendaylight.yangtools.yang.binding.DataObject;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 
 
 /**
- * Tests for @{NodeConnectorInventoryEventTranslator} class.
+ * Tests for {@link NodeConnectorInventoryEventTranslator}.
  */
 @RunWith(MockitoJUnitRunner.class)
 public class NodeConnectorInventoryEventTranslatorTest {
-    static InstanceIdentifier<NodeConnector> id = TestUtils.createNodeConnectorId("openflow:1", "openflow:1:1");
-    static InstanceIdentifier<FlowCapableNodeConnector> iiToConnector = id.augmentation(FlowCapableNodeConnector.class);
-    static FlowCapableNodeConnector fcnc = TestUtils.createFlowCapableNodeConnector().build();
+    private static final InstanceIdentifier<NodeConnector> id = TestUtils.createNodeConnectorId("openflow:1", "openflow:1:1");
+    private static final InstanceIdentifier<FlowCapableNodeConnector> iiToConnector = id.augmentation(FlowCapableNodeConnector.class);
+    private static final FlowCapableNodeConnector fcnc = TestUtils.createFlowCapableNodeConnector().build();
 
-    @Mock DataBroker dataBroker;
-    @Mock ListenerRegistration<DataChangeListener> dataChangeListenerRegistration;
-    @Mock NodeConnectorEventsObserver eventsObserver;
-    @Mock NodeConnectorEventsObserver eventsObserver2;
+    @Mock
+    private NodeConnectorEventsObserver eventsObserver;
+    @Mock
+    private NodeConnectorEventsObserver eventsObserver2;
 
-    MockDataChangedEvent dataChangedEvent = new MockDataChangedEvent();
-    NodeConnectorInventoryEventTranslator translator;
+    private NodeConnectorInventoryEventTranslator translator;
 
     @Before
     public void setUp() {
-
-        when(dataBroker.registerDataChangeListener(
-                any(LogicalDatastoreType.class),
-                any(InstanceIdentifier.class),
-                any(DataChangeListener.class),
-                any(AsyncDataBroker.DataChangeScope.class)))
-                .thenReturn(dataChangeListenerRegistration);
-        translator = new NodeConnectorInventoryEventTranslator(dataBroker, eventsObserver, eventsObserver2);
+        translator = new NodeConnectorInventoryEventTranslator(mock(DataBroker.class), eventsObserver, eventsObserver2);
     }
 
     /**
-     * Test that checks if @{NodeConnectorEventsObserver#nodeConnectorAdded} is called
+     * Test that checks if {@link NodeConnectorEventsObserver#nodeConnectorAdded} is called
      * for each FlowCapableNodeConnector item that @{AsyncDataChangeEvent#getCreatedData} return.
      */
     @Test
     public void testNodeConnectorCreation() {
-        // Setup dataChangedEvent to mock new port creation in inventory
-        dataChangedEvent.created.put(iiToConnector, fcnc);
-
-        // Invoke NodeConnectorInventoryEventTranslator and check result
-        translator.onDataChanged(dataChangedEvent);
+        DataTreeModification dataTreeModification = setupDataTreeChange(WRITE, iiToConnector, fcnc);
+        translator.onDataTreeChanged(Collections.singleton(dataTreeModification));
         verify(eventsObserver).nodeConnectorAdded(id, fcnc);
     }
 
@@ -79,12 +74,8 @@ public class NodeConnectorInventoryEventTranslatorTest {
     @Test
     public void testNodeConnectorCreationLinkDown() {
         FlowCapableNodeConnector fcnc = TestUtils.createFlowCapableNodeConnector(true, false).build();
-
-        // Setup dataChangedEvent to mock new port creation in inventory
-        dataChangedEvent.created.put(id, fcnc);
-
-        // Invoke NodeConnectorInventoryEventTranslator and check result
-        translator.onDataChanged(dataChangedEvent);
+        DataTreeModification dataTreeModification = setupDataTreeChange(WRITE, id, fcnc);
+        translator.onDataTreeChanged(Collections.singleton(dataTreeModification));
         verifyZeroInteractions(eventsObserver);
     }
 
@@ -94,80 +85,63 @@ public class NodeConnectorInventoryEventTranslatorTest {
     @Test
     public void testNodeConnectorCreationAdminDown() {
         FlowCapableNodeConnector fcnc = TestUtils.createFlowCapableNodeConnector(false, true).build();
-
-        // Setup dataChangedEvent to mock new port creation in inventory
-        dataChangedEvent.created.put(id, fcnc);
-
-        // Invoke NodeConnectorInventoryEventTranslator and check result
-        translator.onDataChanged(dataChangedEvent);
+        DataTreeModification dataTreeModification = setupDataTreeChange(WRITE, id, fcnc);
+        translator.onDataTreeChanged(Collections.singleton(dataTreeModification));
         verifyZeroInteractions(eventsObserver);
     }
 
     /**
-     * Test that checks if @{NodeConnectorEventsObserver#nodeConnectorRemoved} is called
+     * Test that checks if {@link NodeConnectorEventsObserver#nodeConnectorRemoved} is called
      * for each FlowCapableNodeConnector item inside @{AsyncDataChangeEvent#getUpdatedData}
      * that have link down state.
      */
     @Test
     public void testNodeConnectorUpdateToLinkDown() {
         FlowCapableNodeConnector fcnc = TestUtils.createFlowCapableNodeConnector(true, false).build();
-
-        // Setup dataChangedEvent to mock link down
-        dataChangedEvent.updated.put(iiToConnector, fcnc);
-
-        // Invoke NodeConnectorInventoryEventTranslator and check result
-        translator.onDataChanged(dataChangedEvent);
+        DataTreeModification dataTreeModification = setupDataTreeChange(SUBTREE_MODIFIED, iiToConnector, fcnc);
+        translator.onDataTreeChanged(Collections.singleton(dataTreeModification));
         verify(eventsObserver).nodeConnectorRemoved(id);
     }
 
     /**
-     * Test that checks if @{NodeConnectorEventsObserver#nodeConnectorRemoved} is called
+     * Test that checks if {@link NodeConnectorEventsObserver#nodeConnectorRemoved} is called
      * for each FlowCapableNodeConnector item inside @{AsyncDataChangeEvent#getUpdatedData}
      * that have administrative down state.
      */
     @Test
     public void testNodeConnectorUpdateToAdminDown() {
         FlowCapableNodeConnector fcnc = TestUtils.createFlowCapableNodeConnector(false, true).build();
-
-        // Setup dataChangedEvent to mock link down and administrative port down
-        dataChangedEvent.updated.put(iiToConnector, fcnc);
-
-        // Invoke NodeConnectorInventoryEventTranslator and check result
-        translator.onDataChanged(dataChangedEvent);
+        DataTreeModification dataTreeModification = setupDataTreeChange(SUBTREE_MODIFIED, iiToConnector, fcnc);
+        translator.onDataTreeChanged(Collections.singleton(dataTreeModification));
         verify(eventsObserver).nodeConnectorRemoved(id);
     }
 
     /**
-     * Test that checks if @{NodeConnectorEventsObserver#nodeConnectorAdded} is called
+     * Test that checks if {@link NodeConnectorEventsObserver#nodeConnectorAdded} is called
      * for each FlowCapableNodeConnector item inside @{AsyncDataChangeEvent#getUpdatedData}
      * that have administrative up and link up state.
      */
     @Test
     public void testNodeConnectorUpdateToUp() {
-        // Setup dataChangedEvent to mock link up and administrative port up
-        dataChangedEvent.updated.put(iiToConnector, fcnc);
-
-        // Invoke NodeConnectorInventoryEventTranslator and check result
-        translator.onDataChanged(dataChangedEvent);
+        DataTreeModification dataTreeModification = setupDataTreeChange(SUBTREE_MODIFIED, iiToConnector, fcnc);
+        translator.onDataTreeChanged(Collections.singleton(dataTreeModification));
         verify(eventsObserver).nodeConnectorAdded(id, fcnc);
     }
 
     /**
-     * Test that checks if @{NodeConnectorEventsObserver#nodeConnectorRemoved} is called
+     * Test that checks if {@link NodeConnectorEventsObserver#nodeConnectorRemoved} is called
      * for each FlowCapableNodeConnector path that @{AsyncDataChangeEvent#getRemovedPaths} return.
      */
     @Test
     public void testNodeConnectorRemoval() {
-        // Setup dataChangedEvent to mock node connector removal
-        dataChangedEvent.removed.add(iiToConnector);
-
+        DataTreeModification dataTreeModification = setupDataTreeChange(DELETE, iiToConnector, null);
         // Invoke NodeConnectorInventoryEventTranslator and check result
-        translator.onDataChanged(dataChangedEvent);
+        translator.onDataTreeChanged(Collections.singleton(dataTreeModification));
         verify(eventsObserver).nodeConnectorRemoved(id);
     }
 
     /**
-     * Test that checks if @{NodeConnectorEventsObserver#nodeConnectorAdded} and
+     * Test that checks if {@link NodeConnectorEventsObserver#nodeConnectorAdded} and
      * @{NodeConnectorEventsObserver#nodeConnectorRemoved} are called for each
      * observer when multiple observers are registered for notifications.
      */
@@ -176,66 +150,32 @@ public class NodeConnectorInventoryEventTranslatorTest {
         // Create prerequisites
         InstanceIdentifier<NodeConnector> id2 = TestUtils.createNodeConnectorId("openflow:1", "openflow:1:2");
         InstanceIdentifier<FlowCapableNodeConnector> iiToConnector2 = id2.augmentation(FlowCapableNodeConnector.class);
-
-        // Setup dataChangedEvent to mock port creation and removal
-        dataChangedEvent.created.put(iiToConnector, fcnc);
-        dataChangedEvent.removed.add(iiToConnector2);
-
+        List<DataTreeModification> modifications = new ArrayList();
+        modifications.add(setupDataTreeChange(WRITE, iiToConnector, fcnc));
+        modifications.add(setupDataTreeChange(DELETE, iiToConnector2, null));
         // Invoke onDataChanged and check that both observers notified
-        translator.onDataChanged(dataChangedEvent);
+        translator.onDataTreeChanged(modifications);
         verify(eventsObserver).nodeConnectorAdded(id, fcnc);
         verify(eventsObserver).nodeConnectorRemoved(id2);
         verify(eventsObserver2).nodeConnectorAdded(id, fcnc);
         verify(eventsObserver2).nodeConnectorRemoved(id2);
     }
 
-    /**
-     * Test that @{ListenerRegistration} is closed when ${NodeConnectorInventoryEventTranslator#close}
-     * method is called.
-     * @throws Exception
-     */
     @Test
-    public void testCleanup() throws Exception {
-        // Trigger cleanup
+    public void tearDown() throws Exception {
         translator.close();
-
-        // Verify that ListenerRegistration to DOM events
-        verify(dataChangeListenerRegistration, times(2)).close();
     }
 
-    static class MockDataChangedEvent implements AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> {
-        Map<InstanceIdentifier<?>,DataObject> created = new HashMap<>();
-        Map<InstanceIdentifier<?>,DataObject> updated = new HashMap<>();
-        Set<InstanceIdentifier<?>> removed = new HashSet<>();
-
-        @Override
-        public Map<InstanceIdentifier<?>, DataObject> getCreatedData() {
-            return created;
-        }
-
-        @Override
-        public Map<InstanceIdentifier<?>, DataObject> getUpdatedData() {
-            return updated;
-        }
-
-        @Override
-        public Set<InstanceIdentifier<?>> getRemovedPaths() {
-            return removed;
-        }
-
-        @Override
-        public Map<InstanceIdentifier<?>, DataObject> getOriginalData() {
-            throw new UnsupportedOperationException("Not implemented by mock");
-        }
-
-        @Override
-        public DataObject getOriginalSubtree() {
-            throw new UnsupportedOperationException("Not implemented by mock");
-        }
-
-        @Override
-        public DataObject getUpdatedSubtree() {
-            throw new UnsupportedOperationException("Not implemented by mock");
-        }
+    private <T extends DataObject> DataTreeModification setupDataTreeChange(final ModificationType type,
+                                                            final InstanceIdentifier<T> ii,
+                                                            final FlowCapableNodeConnector connector) {
+        final DataTreeModification dataTreeModification = mock(DataTreeModification.class);
+        when(dataTreeModification.getRootNode()).thenReturn(mock(DataObjectModification.class));
+        DataTreeIdentifier<T> identifier = new DataTreeIdentifier(LogicalDatastoreType.OPERATIONAL, ii);
+        when(dataTreeModification.getRootNode().getModificationType()).thenReturn(type);
+        when(dataTreeModification.getRootPath()).thenReturn(identifier);
+        when(dataTreeModification.getRootNode().getDataAfter()).thenReturn(connector);
+        return dataTreeModification;
+
     }
 }
index 422f4e55dd50e105b1b3fd66fb0079e27eb000bb..e6ab666b65a0405e66194ed651f3d943068cf00c 100644 (file)
@@ -45,7 +45,7 @@ public class TestUtils {
         return createFlowCapableNodeConnector(false, false, mac, port);
     }
 
-    static FlowCapableNodeConnectorBuilder createFlowCapableNodeConnector(boolean linkDown, boolean adminDown,
+    private static FlowCapableNodeConnectorBuilder createFlowCapableNodeConnector(boolean linkDown, boolean adminDown,
                                                                           MacAddress mac, long port) {
         return new FlowCapableNodeConnectorBuilder()
                 .setHardwareAddress(mac)
index 097d0edc4ebc0089c11375afa782ad9577ccb387..43225b987028b82f20baf4416a71dd9d3fbd1425 100644 (file)
@@ -1,4 +1,4 @@
-/*
+/**
  * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
  *
  * This program and the accompanying materials are made available under the
@@ -14,12 +14,8 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.topology.discovery.rev
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorRef;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.PacketProcessingListener;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.PacketReceived;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 
 public class LLDPDiscoveryListener implements PacketProcessingListener {
-    private static final Logger LOG = LoggerFactory.getLogger(LLDPDiscoveryListener.class);
-
     private final LLDPLinkAger lldpLinkAger;
     private final NotificationProviderService notificationService;
 
index 9828888c835f2feb83d22047e21cb96122e3490b..61c737efa9998a4f5237cce17cb1f69467f8bc5c 100644 (file)
@@ -15,6 +15,7 @@ import java.util.List;
 import java.util.Optional;
 import javax.annotation.CheckForNull;
 import org.opendaylight.openflowplugin.api.OFConstants;
+import org.opendaylight.openflowplugin.impl.util.GroupUtil;
 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorExecutor;
 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.data.VersionConvertorData;
 import org.opendaylight.openflowplugin.openflow.md.util.OpenflowPortsUtil;
@@ -50,7 +51,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.Meter
 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.MeterKbps;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.MeterPktps;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.MeterStats;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.ActionType;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.desc._case.MultipartReplyDesc;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.group.features._case.MultipartReplyGroupFeatures;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.meter.features._case.MultipartReplyMeterFeatures;
@@ -158,28 +158,7 @@ public class NodeStaticReplyTranslatorUtil {
         addGroupCapabilities(reply, gCapability);
         groupFeature.setGroupCapabilitiesSupported(gCapability);
 
-        final List<Long> supportActionByGroups = new ArrayList<>();
-        for (final ActionType actionType : reply.getActionsBitmap()) {
-            long supportActionBitmap = 0;
-            supportActionBitmap |= actionType.isOFPATOUTPUT() ? (1 << 0) : 0;
-            supportActionBitmap |= actionType.isOFPATCOPYTTLOUT() ? (1 << 11) : 0;
-            supportActionBitmap |= actionType.isOFPATCOPYTTLIN() ? (1 << 12) : 0;
-            supportActionBitmap |= actionType.isOFPATSETMPLSTTL() ? (1 << 15) : 0;
-            supportActionBitmap |= actionType.isOFPATDECMPLSTTL() ? (1 << 16) : 0;
-            supportActionBitmap |= actionType.isOFPATPUSHVLAN() ? (1 << 17) : 0;
-            supportActionBitmap |= actionType.isOFPATPOPVLAN() ? (1 << 18) : 0;
-            supportActionBitmap |= actionType.isOFPATPUSHMPLS() ? (1 << 19) : 0;
-            supportActionBitmap |= actionType.isOFPATPOPMPLS() ? (1 << 20) : 0;
-            supportActionBitmap |= actionType.isOFPATSETQUEUE() ? (1 << 21) : 0;
-            supportActionBitmap |= actionType.isOFPATGROUP() ? (1 << 22) : 0;
-            supportActionBitmap |= actionType.isOFPATSETNWTTL() ? (1 << 23) : 0;
-            supportActionBitmap |= actionType.isOFPATDECNWTTL() ? (1 << 24) : 0;
-            supportActionBitmap |= actionType.isOFPATSETFIELD() ? (1 << 25) : 0;
-            supportActionBitmap |= actionType.isOFPATPUSHPBB() ? (1 << 26) : 0;
-            supportActionBitmap |= actionType.isOFPATPOPPBB() ? (1 << 27) : 0;
-            supportActionByGroups.add(Long.valueOf(supportActionBitmap));
-        }
-        groupFeature.setActions(supportActionByGroups);
+        groupFeature.setActions(GroupUtil.extractGroupActionsSupportBitmap(reply.getActionsBitmap()));
         return new NodeGroupFeaturesBuilder().setGroupFeatures(groupFeature.build()).build();
     }
 
index 57e86731f8eb336ae6825fbb7c276a9811fad5ba..546e57119aa2c9e931f6467b8625cf505d3b42e4 100644 (file)
@@ -87,7 +87,7 @@ abstract class AbstractService<I, O> {
         return messageSpy;
     }
 
-    protected abstract OfHeader buildRequest(Xid xid, I input) throws Exception;
+    protected abstract OfHeader buildRequest(Xid xid, I input) throws ServiceException;
 
     protected abstract FutureCallback<OfHeader> createCallback(RequestContext<O> context, Class<?> requestType);
 
index 8afe07ea2ff29b5435e4989944323ac27f555d94..0bf4a5bba7232cd00041aa2ae7ade503f1e8e98e 100644 (file)
@@ -20,7 +20,7 @@ public class EchoService extends AbstractSimpleService<EchoInputBuilder, EchoOut
     }
 
     @Override
-    protected OfHeader buildRequest(final Xid xid, final EchoInputBuilder input) throws Exception {
+    protected OfHeader buildRequest(final Xid xid, final EchoInputBuilder input) throws ServiceException {
         return input
                 .setXid(xid.getValue())
                 .setVersion(getVersion())
index bbba541d3d630be96aa732f918c7f36fce8a9b4b..f319947cf34df9761de337ea37fabcaf9053f0bf 100644 (file)
@@ -28,7 +28,7 @@ public class FlowCapableTransactionServiceImpl extends AbstractVoidService<SendB
     }
 
     @Override
-    protected OfHeader buildRequest(final Xid xid, final SendBarrierInput input) {
+    protected OfHeader buildRequest(final Xid xid, final SendBarrierInput input) throws ServiceException {
         final BarrierInputBuilder barrierInputOFJavaBuilder = new BarrierInputBuilder();
         barrierInputOFJavaBuilder.setVersion(getVersion());
         barrierInputOFJavaBuilder.setXid(xid.getValue());
index e3fbb01c027ddf5ceea8bcdf758d98de160974c7..e865d903309eb989b4cccb051cab52eacd481c2e 100644 (file)
@@ -42,7 +42,7 @@ final class FlowService<O extends DataObject> extends AbstractSimpleService<Flow
     }
 
     @Override
-    protected OfHeader buildRequest(final Xid xid, final FlowModInputBuilder input) {
+    protected OfHeader buildRequest(final Xid xid, final FlowModInputBuilder input) throws ServiceException {
         input.setXid(xid.getValue());
         return input.build();
     }
index d0f50eaa74a0de2792473859c680a050509ad25d..aa1ebe15ccf02e0fcb808fe3c9321f63f68f350b 100644 (file)
@@ -31,7 +31,7 @@ final class GroupService<I extends Group, O extends DataObject> extends Abstract
     }
 
     @Override
-    protected OfHeader buildRequest(final Xid xid, final I input) {
+    protected OfHeader buildRequest(final Xid xid, final I input) throws ServiceException {
         final Optional<GroupModInputBuilder> ofGroupModInput = convertorExecutor.convert(input, data);
 
         final GroupModInputBuilder groupModInputBuilder = ofGroupModInput
index 91d4abbacbdca82c53c9c2b27cd837ef2477c752..7b6fc8e69b7f123fbdf8cec2717638cda287f5b8 100644 (file)
@@ -31,7 +31,7 @@ final class MeterService<I extends Meter, O extends DataObject> extends Abstract
     }
 
     @Override
-    protected OfHeader buildRequest(final Xid xid, final I input) {
+    protected OfHeader buildRequest(final Xid xid, final I input) throws ServiceException {
         final Optional<MeterModInputBuilder> ofMeterModInput = convertorExecutor.convert(input, data);
         final MeterModInputBuilder meterModInputBuilder = ofMeterModInput
                 .orElse(MeterConvertor.defaultResult(getVersion()));
index 420dc80827b4209d86296f76fafbe09b12f01436..5a45f44336de19ddf9f3c92443a5bc7721c197bf 100644 (file)
@@ -30,7 +30,7 @@ public final class NodeConfigServiceImpl extends AbstractSimpleService<SetConfig
     }
 
     @Override
-    protected OfHeader buildRequest(final Xid xid, final SetConfigInput input) {
+    protected OfHeader buildRequest(final Xid xid, final SetConfigInput input) throws ServiceException {
         SetConfigInputBuilder builder = new SetConfigInputBuilder();
         SwitchConfigFlag flag = SwitchConfigFlag.valueOf(input.getFlag());
 
index b8449e49545e50faba0a24de2fa137847750fe35..e32dbb5337d5fcb67703c41b073860740f2d1959 100644 (file)
@@ -36,7 +36,7 @@ public final class PacketProcessingServiceImpl extends AbstractVoidService<Trans
     }
 
     @Override
-    protected OfHeader buildRequest(final Xid xid, final TransmitPacketInput input) {
+    protected OfHeader buildRequest(final Xid xid, final TransmitPacketInput input) throws ServiceException {
         final PacketOutConvertorData data = new PacketOutConvertorData(getVersion());
         data.setDatapathId(getDatapathId());
         data.setXid(xid.getValue());
index de1ad3efea2b1e887d0f349537aa839348573fdf..c2653bf20803c14d2e6f491fd96608019f79a07a 100644 (file)
@@ -47,7 +47,7 @@ public class RoleService extends AbstractSimpleService<RoleRequestInputBuilder,
     }
 
     @Override
-    protected OfHeader buildRequest(final Xid xid, final RoleRequestInputBuilder input) {
+    protected OfHeader buildRequest(final Xid xid, final RoleRequestInputBuilder input) throws ServiceException {
         input.setXid(xid.getValue());
         return input.build();
     }
index 6baeda6c3a784ead8f9730620a20a841c271389f..b1969eb08dca33f12f041bf0526e1ca44c950fd8 100644 (file)
@@ -37,21 +37,28 @@ public class SalExperimenterMessageServiceImpl extends AbstractVoidService<SendE
     }
 
     @Override
-    protected OfHeader buildRequest(Xid xid, SendExperimenterInput input) throws ConversionException {
+    protected OfHeader buildRequest(Xid xid, SendExperimenterInput input) throws ServiceException {
         final TypeVersionKey key = new TypeVersionKey(input.getExperimenterMessageOfChoice().getImplementedInterface(), getVersion());
         final ConvertorMessageToOFJava<ExperimenterMessageOfChoice, ExperimenterDataOfChoice> messageConverter =
                 extensionConverterProvider.getMessageConverter(key);
 
         if (messageConverter == null) {
-            throw new ConverterNotFoundException(key.toString());
+            throw new ServiceException(new ConverterNotFoundException(key.toString()));
         }
-        
-        final ExperimenterInputBuilder experimenterInputBld = new ExperimenterInputBuilder()
-                .setExperimenter(messageConverter.getExperimenterId())
-                .setExpType(messageConverter.getType())
-                .setExperimenterDataOfChoice(messageConverter.convert(input.getExperimenterMessageOfChoice()))
-                .setVersion(getVersion())
-                .setXid(xid.getValue());
+
+        final ExperimenterInputBuilder experimenterInputBld;
+
+        try {
+            experimenterInputBld = new ExperimenterInputBuilder()
+                    .setExperimenter(messageConverter.getExperimenterId())
+                    .setExpType(messageConverter.getType())
+                    .setExperimenterDataOfChoice(messageConverter.convert(input.getExperimenterMessageOfChoice()))
+                    .setVersion(getVersion())
+                    .setXid(xid.getValue());
+        } catch (ConversionException e) {
+            throw new ServiceException(e);
+        }
+
         return experimenterInputBld.build();
     }
 
index 05a88b15333626c1d6d09881ef460f43884a70f9..0967ffa0d18cc628a9c8a36d91ba650eed1e0a0a 100644 (file)
@@ -120,58 +120,7 @@ public class SalFlatBatchServiceImpl implements SalFlatBatchService {
                 LOG.trace("batch progressing on step type {}", planStep.getStepType());
                 LOG.trace("batch progressing previous steps result: {}", chainInput.isSuccessful());
 
-                final ListenableFuture<RpcResult<ProcessFlatBatchOutput>> chainOutput;
-                switch (planStep.getStepType()) {
-                    case FLOW_ADD:
-                        final AddFlowsBatchInput addFlowsBatchInput = FlatBatchFlowAdapters.adaptFlatBatchAddFlow(planStep, node);
-                        final Future<RpcResult<AddFlowsBatchOutput>> resultAddFlowFuture = salFlowService.addFlowsBatch(addFlowsBatchInput);
-                        chainOutput = FlatBatchFlowAdapters.convertFlowBatchFutureForChain(resultAddFlowFuture, currentOffset);
-                        break;
-                    case FLOW_REMOVE:
-                        final RemoveFlowsBatchInput removeFlowsBatchInput = FlatBatchFlowAdapters.adaptFlatBatchRemoveFlow(planStep, node);
-                        final Future<RpcResult<RemoveFlowsBatchOutput>> resultRemoveFlowFuture = salFlowService.removeFlowsBatch(removeFlowsBatchInput);
-                        chainOutput = FlatBatchFlowAdapters.convertFlowBatchFutureForChain(resultRemoveFlowFuture, currentOffset);
-                        break;
-                    case FLOW_UPDATE:
-                        final UpdateFlowsBatchInput updateFlowsBatchInput = FlatBatchFlowAdapters.adaptFlatBatchUpdateFlow(planStep, node);
-                        final Future<RpcResult<UpdateFlowsBatchOutput>> resultUpdateFlowFuture = salFlowService.updateFlowsBatch(updateFlowsBatchInput);
-                        chainOutput = FlatBatchFlowAdapters.convertFlowBatchFutureForChain(resultUpdateFlowFuture, currentOffset);
-                        break;
-                    case GROUP_ADD:
-                        final AddGroupsBatchInput addGroupsBatchInput = FlatBatchGroupAdapters.adaptFlatBatchAddGroup(planStep, node);
-                        final Future<RpcResult<AddGroupsBatchOutput>> resultAddGroupFuture = salGroupService.addGroupsBatch(addGroupsBatchInput);
-                        chainOutput = FlatBatchGroupAdapters.convertGroupBatchFutureForChain(resultAddGroupFuture, currentOffset);
-                        break;
-                    case GROUP_REMOVE:
-                        final RemoveGroupsBatchInput removeGroupsBatchInput = FlatBatchGroupAdapters.adaptFlatBatchRemoveGroup(planStep, node);
-                        final Future<RpcResult<RemoveGroupsBatchOutput>> resultRemoveGroupFuture = salGroupService.removeGroupsBatch(removeGroupsBatchInput);
-                        chainOutput = FlatBatchGroupAdapters.convertGroupBatchFutureForChain(resultRemoveGroupFuture, currentOffset);
-                        break;
-                    case GROUP_UPDATE:
-                        final UpdateGroupsBatchInput updateGroupsBatchInput = FlatBatchGroupAdapters.adaptFlatBatchUpdateGroup(planStep, node);
-                        final Future<RpcResult<UpdateGroupsBatchOutput>> resultUpdateGroupFuture = salGroupService.updateGroupsBatch(updateGroupsBatchInput);
-                        chainOutput = FlatBatchGroupAdapters.convertGroupBatchFutureForChain(resultUpdateGroupFuture, currentOffset);
-                        break;
-                    case METER_ADD:
-                        final AddMetersBatchInput addMetersBatchInput = FlatBatchMeterAdapters.adaptFlatBatchAddMeter(planStep, node);
-                        final Future<RpcResult<AddMetersBatchOutput>> resultAddMeterFuture = salMeterService.addMetersBatch(addMetersBatchInput);
-                        chainOutput = FlatBatchMeterAdapters.convertMeterBatchFutureForChain(resultAddMeterFuture, currentOffset);
-                        break;
-                    case METER_REMOVE:
-                        final RemoveMetersBatchInput removeMetersBatchInput = FlatBatchMeterAdapters.adaptFlatBatchRemoveMeter(planStep, node);
-                        final Future<RpcResult<RemoveMetersBatchOutput>> resultRemoveMeterFuture = salMeterService.removeMetersBatch(removeMetersBatchInput);
-                        chainOutput = FlatBatchMeterAdapters.convertMeterBatchFutureForChain(resultRemoveMeterFuture, currentOffset);
-                        break;
-                    case METER_UPDATE:
-                        final UpdateMetersBatchInput updateMetersBatchInput = FlatBatchMeterAdapters.adaptFlatBatchUpdateMeter(planStep, node);
-                        final Future<RpcResult<UpdateMetersBatchOutput>> resultUpdateMeterFuture = salMeterService.updateMetersBatch(updateMetersBatchInput);
-                        chainOutput = FlatBatchMeterAdapters.convertMeterBatchFutureForChain(resultUpdateMeterFuture, currentOffset);
-                        break;
-                    default:
-                        LOG.warn("Unsupported plan-step type occurred: {} -> OMITTING", planStep.getStepType());
-                        chainOutput = FlatBatchUtil.createEmptyRpcBatchResultFuture(true);
-                }
-                return chainOutput;
+                return getChainOutput(node, planStep, currentOffset);
             }));
             stepOffset += planStep.getTaskBag().size();
         }
@@ -179,4 +128,62 @@ public class SalFlatBatchServiceImpl implements SalFlatBatchService {
         return chainJobs;
     }
 
+    private ListenableFuture<RpcResult<ProcessFlatBatchOutput>> getChainOutput(final NodeRef node,
+                                                                               final BatchPlanStep planStep,
+                                                                               final int currentOffset) {
+        final ListenableFuture<RpcResult<ProcessFlatBatchOutput>> chainOutput;
+
+        switch (planStep.getStepType()) {
+            case FLOW_ADD:
+                final AddFlowsBatchInput addFlowsBatchInput = FlatBatchFlowAdapters.adaptFlatBatchAddFlow(planStep, node);
+                final Future<RpcResult<AddFlowsBatchOutput>> resultAddFlowFuture = salFlowService.addFlowsBatch(addFlowsBatchInput);
+                chainOutput = FlatBatchFlowAdapters.convertFlowBatchFutureForChain(resultAddFlowFuture, currentOffset);
+                break;
+            case FLOW_REMOVE:
+                final RemoveFlowsBatchInput removeFlowsBatchInput = FlatBatchFlowAdapters.adaptFlatBatchRemoveFlow(planStep, node);
+                final Future<RpcResult<RemoveFlowsBatchOutput>> resultRemoveFlowFuture = salFlowService.removeFlowsBatch(removeFlowsBatchInput);
+                chainOutput = FlatBatchFlowAdapters.convertFlowBatchFutureForChain(resultRemoveFlowFuture, currentOffset);
+                break;
+            case FLOW_UPDATE:
+                final UpdateFlowsBatchInput updateFlowsBatchInput = FlatBatchFlowAdapters.adaptFlatBatchUpdateFlow(planStep, node);
+                final Future<RpcResult<UpdateFlowsBatchOutput>> resultUpdateFlowFuture = salFlowService.updateFlowsBatch(updateFlowsBatchInput);
+                chainOutput = FlatBatchFlowAdapters.convertFlowBatchFutureForChain(resultUpdateFlowFuture, currentOffset);
+                break;
+            case GROUP_ADD:
+                final AddGroupsBatchInput addGroupsBatchInput = FlatBatchGroupAdapters.adaptFlatBatchAddGroup(planStep, node);
+                final Future<RpcResult<AddGroupsBatchOutput>> resultAddGroupFuture = salGroupService.addGroupsBatch(addGroupsBatchInput);
+                chainOutput = FlatBatchGroupAdapters.convertGroupBatchFutureForChain(resultAddGroupFuture, currentOffset);
+                break;
+            case GROUP_REMOVE:
+                final RemoveGroupsBatchInput removeGroupsBatchInput = FlatBatchGroupAdapters.adaptFlatBatchRemoveGroup(planStep, node);
+                final Future<RpcResult<RemoveGroupsBatchOutput>> resultRemoveGroupFuture = salGroupService.removeGroupsBatch(removeGroupsBatchInput);
+                chainOutput = FlatBatchGroupAdapters.convertGroupBatchFutureForChain(resultRemoveGroupFuture, currentOffset);
+                break;
+            case GROUP_UPDATE:
+                final UpdateGroupsBatchInput updateGroupsBatchInput = FlatBatchGroupAdapters.adaptFlatBatchUpdateGroup(planStep, node);
+                final Future<RpcResult<UpdateGroupsBatchOutput>> resultUpdateGroupFuture = salGroupService.updateGroupsBatch(updateGroupsBatchInput);
+                chainOutput = FlatBatchGroupAdapters.convertGroupBatchFutureForChain(resultUpdateGroupFuture, currentOffset);
+                break;
+            case METER_ADD:
+                final AddMetersBatchInput addMetersBatchInput = FlatBatchMeterAdapters.adaptFlatBatchAddMeter(planStep, node);
+                final Future<RpcResult<AddMetersBatchOutput>> resultAddMeterFuture = salMeterService.addMetersBatch(addMetersBatchInput);
+                chainOutput = FlatBatchMeterAdapters.convertMeterBatchFutureForChain(resultAddMeterFuture, currentOffset);
+                break;
+            case METER_REMOVE:
+                final RemoveMetersBatchInput removeMetersBatchInput = FlatBatchMeterAdapters.adaptFlatBatchRemoveMeter(planStep, node);
+                final Future<RpcResult<RemoveMetersBatchOutput>> resultRemoveMeterFuture = salMeterService.removeMetersBatch(removeMetersBatchInput);
+                chainOutput = FlatBatchMeterAdapters.convertMeterBatchFutureForChain(resultRemoveMeterFuture, currentOffset);
+                break;
+            case METER_UPDATE:
+                final UpdateMetersBatchInput updateMetersBatchInput = FlatBatchMeterAdapters.adaptFlatBatchUpdateMeter(planStep, node);
+                final Future<RpcResult<UpdateMetersBatchOutput>> resultUpdateMeterFuture = salMeterService.updateMetersBatch(updateMetersBatchInput);
+                chainOutput = FlatBatchMeterAdapters.convertMeterBatchFutureForChain(resultUpdateMeterFuture, currentOffset);
+                break;
+            default:
+                LOG.warn("Unsupported plan-step type occurred: {} -> OMITTING", planStep.getStepType());
+                chainOutput = FlatBatchUtil.createEmptyRpcBatchResultFuture(true);
+        }
+
+        return chainOutput;
+    }
 }
index 8000e8e1245e8bf30e50079081b342872b48b3a0..db4fb135fdf9d95467c0b7eeee9334b323b63284 100644 (file)
@@ -78,47 +78,9 @@ public class SalFlowServiceImpl implements SalFlowService, ItemLifeCycleSource {
     @Override
     public Future<RpcResult<AddFlowOutput>> addFlow(final AddFlowInput input) {
         final FlowRegistryKey flowRegistryKey = FlowRegistryKeyFactory.create(input);
-
         final ListenableFuture<RpcResult<AddFlowOutput>> future =
                 flowAdd.processFlowModInputBuilders(flowAdd.toFlowModInputs(input));
-        Futures.addCallback(future, new FutureCallback<RpcResult<AddFlowOutput>>() {
-            @Override
-            public void onSuccess(final RpcResult<AddFlowOutput> rpcResult) {
-                if (rpcResult.isSuccessful()) {
-                    final FlowId flowId;
-                    final FlowDescriptor flowDescriptor;
-
-                    if (Objects.nonNull(input.getFlowRef())) {
-                        flowId = input.getFlowRef().getValue().firstKeyOf(Flow.class, FlowKey.class).getId();
-                        flowDescriptor = FlowDescriptorFactory.create(input.getTableId(), flowId);
-                        deviceContext.getDeviceFlowRegistry().store(flowRegistryKey, flowDescriptor);
-
-                    } else {
-                        flowId = deviceContext.getDeviceFlowRegistry().storeIfNecessary(flowRegistryKey);
-                        flowDescriptor = FlowDescriptorFactory.create(input.getTableId(), flowId);
-                    }
-
-                    if(LOG.isDebugEnabled()) {
-                        LOG.debug("flow add with id={},finished without error,", flowId.getValue());
-                    }
-                    if (itemLifecycleListener != null) {
-                        KeyedInstanceIdentifier<Flow, FlowKey> flowPath = createFlowPath(flowDescriptor,
-                                deviceContext.getDeviceInfo().getNodeInstanceIdentifier());
-                        final FlowBuilder flowBuilder = new FlowBuilder(input).setId(flowDescriptor.getFlowId());
-                        itemLifecycleListener.onAdded(flowPath, flowBuilder.build());
-                    }
-                } else {
-                    deviceContext.getDeviceFlowRegistry().markToBeremoved(flowRegistryKey);
-                    LOG.error("flow add failed for flow={}, errors={}", input.toString(),
-                            errorsToString(rpcResult.getErrors()));
-                }
-            }
-
-            @Override
-            public void onFailure(final Throwable throwable) {
-               LOG.error("Service call for adding flow={} failed, reason {} .", input.toString(), throwable);
-            }
-        });
+        Futures.addCallback(future, new AddFlowCallback(input, flowRegistryKey));
 
         return future;
     }
@@ -129,34 +91,7 @@ public class SalFlowServiceImpl implements SalFlowService, ItemLifeCycleSource {
 
         final ListenableFuture<RpcResult<RemoveFlowOutput>> future =
                 flowRemove.processFlowModInputBuilders(flowRemove.toFlowModInputs(input));
-        Futures.addCallback(future, new FutureCallback<RpcResult<RemoveFlowOutput>>() {
-            @Override
-            public void onSuccess(final RpcResult<RemoveFlowOutput> result) {
-                if (result.isSuccessful()) {
-                    if(LOG.isDebugEnabled()) {
-                        LOG.debug("flow removed finished without error,");
-                    }
-                    FlowRegistryKey flowRegistryKey = FlowRegistryKeyFactory.create(input);
-                    deviceContext.getDeviceFlowRegistry().markToBeremoved(flowRegistryKey);
-                    if (itemLifecycleListener != null) {
-                        final FlowDescriptor flowDescriptor =
-                                deviceContext.getDeviceFlowRegistry().retrieveIdForFlow(flowRegistryKey);
-                        if (flowDescriptor != null) {
-                            KeyedInstanceIdentifier<Flow, FlowKey> flowPath = createFlowPath(flowDescriptor,
-                                    deviceContext.getDeviceInfo().getNodeInstanceIdentifier());
-                            itemLifecycleListener.onRemoved(flowPath);
-                        }
-                    }
-                } else {
-                    LOG.error("Flow remove failed with errors : {}",errorsToString(result.getErrors()));
-                }
-            }
-
-            @Override
-            public void onFailure(final Throwable throwable) {
-                LOG.error("Service call for removing flow with id {} failed ,reason {}",input.getFlowRef().getValue(), throwable);
-            }
-        });
+        Futures.addCallback(future, new RemoveFlowCallback(input));
 
         return future;
     }
@@ -173,9 +108,8 @@ public class SalFlowServiceImpl implements SalFlowService, ItemLifeCycleSource {
 
     @Override
     public Future<RpcResult<UpdateFlowOutput>> updateFlow(final UpdateFlowInput input) {
-        final UpdateFlowInput in = input;
-        final UpdatedFlow updated = in.getUpdatedFlow();
-        final OriginalFlow original = in.getOriginalFlow();
+        final UpdatedFlow updated = input.getUpdatedFlow();
+        final OriginalFlow original = input.getOriginalFlow();
 
         final List<FlowModInputBuilder> allFlowMods = new ArrayList<>();
         final List<FlowModInputBuilder> ofFlowModInputs;
@@ -196,60 +130,150 @@ public class SalFlowServiceImpl implements SalFlowService, ItemLifeCycleSource {
 
         allFlowMods.addAll(ofFlowModInputs);
         ListenableFuture<RpcResult<UpdateFlowOutput>> future = flowUpdate.processFlowModInputBuilders(allFlowMods);
-        Futures.addCallback(future, new FutureCallback<RpcResult<UpdateFlowOutput>>() {
-            @Override
-            public void onSuccess(final RpcResult<UpdateFlowOutput> o) {
-                FlowRegistryKey flowRegistryKey = FlowRegistryKeyFactory.create(original);
+        Futures.addCallback(future, new UpdateFlowCallback(input));
+        return future;
+    }
+
+    @VisibleForTesting
+    static KeyedInstanceIdentifier<Flow, FlowKey> createFlowPath(FlowDescriptor flowDescriptor,
+                                                                 KeyedInstanceIdentifier<Node, NodeKey> nodePath) {
+        return nodePath.augmentation(FlowCapableNode.class)
+                .child(Table.class, flowDescriptor.getTableKey())
+                .child(Flow.class, new FlowKey(flowDescriptor.getFlowId()));
+    }
 
-                FlowRegistryKey updatedflowRegistryKey = FlowRegistryKeyFactory.create(updated);
-                final FlowRef flowRef = input.getFlowRef();
-                final DeviceFlowRegistry deviceFlowRegistry = deviceContext.getDeviceFlowRegistry();
+    private class AddFlowCallback implements FutureCallback<RpcResult<AddFlowOutput>> {
+        private final AddFlowInput input;
+        private final FlowRegistryKey flowRegistryKey;
 
-                if (flowRef == null) { //then this is equivalent to a delete
-                    deviceFlowRegistry.markToBeremoved(flowRegistryKey);
+        private AddFlowCallback(final AddFlowInput input,
+                                final FlowRegistryKey flowRegistryKey) {
+            this.input = input;
+            this.flowRegistryKey = flowRegistryKey;
+        }
 
-                    if (itemLifecycleListener != null) {
-                        final FlowDescriptor flowDescriptor =
-                                deviceContext.getDeviceFlowRegistry().retrieveIdForFlow( flowRegistryKey);
-                        KeyedInstanceIdentifier<Flow, FlowKey> flowPath = createFlowPath(flowDescriptor,
-                                deviceContext.getDeviceInfo().getNodeInstanceIdentifier());
-                        itemLifecycleListener.onRemoved(flowPath);
-                    }
-                } else { //this is either an add or an update
-                    final FlowId flowId = flowRef.getValue().firstKeyOf(Flow.class, FlowKey.class).getId();
-                    final FlowDescriptor flowDescriptor = FlowDescriptorFactory.create(updated.getTableId(), flowId);
-                    deviceFlowRegistry.store(updatedflowRegistryKey, flowDescriptor);
+        @Override
+        public void onSuccess(final RpcResult<AddFlowOutput> rpcResult) {
+            if (rpcResult.isSuccessful()) {
+                final FlowDescriptor flowDescriptor;
+
+                if (Objects.nonNull(input.getFlowRef())) {
+                    final FlowId flowId = input.getFlowRef().getValue().firstKeyOf(Flow.class, FlowKey.class).getId();
+                    flowDescriptor = FlowDescriptorFactory.create(input.getTableId(), flowId);
+                    deviceContext.getDeviceFlowRegistry().store(flowRegistryKey, flowDescriptor);
+                } else {
+                    final FlowId flowId = deviceContext.getDeviceFlowRegistry().storeIfNecessary(flowRegistryKey);
+                    flowDescriptor = FlowDescriptorFactory.create(input.getTableId(), flowId);
+                }
 
-                    if (itemLifecycleListener != null) {
+                LOG.debug("flow add with id={},finished without error,", flowDescriptor.getFlowId().getValue());
+
+                if (itemLifecycleListener != null) {
+                    KeyedInstanceIdentifier<Flow, FlowKey> flowPath = createFlowPath(flowDescriptor,
+                            deviceContext.getDeviceInfo().getNodeInstanceIdentifier());
+                    final FlowBuilder flowBuilder = new FlowBuilder(input).setId(flowDescriptor.getFlowId());
+                    itemLifecycleListener.onAdded(flowPath, flowBuilder.build());
+                }
+            } else {
+                LOG.error("flow add failed for flow={}, errors={}", input.toString(), errorsToString(rpcResult.getErrors()));
+            }
+        }
+
+        @Override
+        public void onFailure(final Throwable throwable) {
+            LOG.error("Service call for adding flow={} failed, reason {} .", input.toString(), throwable);
+        }
+    }
+
+    private class RemoveFlowCallback implements FutureCallback<RpcResult<RemoveFlowOutput>> {
+        private final RemoveFlowInput input;
+
+        private RemoveFlowCallback(final RemoveFlowInput input) {
+            this.input = input;
+        }
+
+        @Override
+        public void onSuccess(final RpcResult<RemoveFlowOutput> result) {
+            if (result.isSuccessful()) {
+                if(LOG.isDebugEnabled()) {
+                    LOG.debug("flow removed finished without error,");
+                }
+                FlowRegistryKey flowRegistryKey = FlowRegistryKeyFactory.create(input);
+                deviceContext.getDeviceFlowRegistry().markToBeremoved(flowRegistryKey);
+                if (itemLifecycleListener != null) {
+                    final FlowDescriptor flowDescriptor =
+                            deviceContext.getDeviceFlowRegistry().retrieveIdForFlow(flowRegistryKey);
+                    if (flowDescriptor != null) {
                         KeyedInstanceIdentifier<Flow, FlowKey> flowPath = createFlowPath(flowDescriptor,
                                 deviceContext.getDeviceInfo().getNodeInstanceIdentifier());
-                        final FlowBuilder flowBuilder = new FlowBuilder(
-                                                    input.getUpdatedFlow()).setId(flowDescriptor.getFlowId());
-
-                        boolean isUpdate = null !=
-                                            deviceFlowRegistry.retrieveIdForFlow(flowRegistryKey);
-                        if (isUpdate) {
-                            itemLifecycleListener.onUpdated(flowPath, flowBuilder.build());
-                        } else {
-                            itemLifecycleListener.onAdded(flowPath, flowBuilder.build());
-                        }
+                        itemLifecycleListener.onRemoved(flowPath);
                     }
                 }
+            } else {
+                LOG.error("Flow remove failed with errors : {}",errorsToString(result.getErrors()));
             }
+        }
 
-            @Override
-            public void onFailure(final Throwable throwable) {
-                LOG.error("Service call for updating flow failed, reason{}", throwable);
-            }
-        });
-        return future;
+        @Override
+        public void onFailure(final Throwable throwable) {
+            LOG.error("Service call for removing flow with id {} failed ,reason {}",input.getFlowRef().getValue(), throwable);
+        }
     }
 
-    @VisibleForTesting
-    static KeyedInstanceIdentifier<Flow, FlowKey> createFlowPath(FlowDescriptor flowDescriptor,
-                                                                 KeyedInstanceIdentifier<Node, NodeKey> nodePath) {
-        return nodePath.augmentation(FlowCapableNode.class)
-                .child(Table.class, flowDescriptor.getTableKey())
-                .child(Flow.class, new FlowKey(flowDescriptor.getFlowId()));
+    private class UpdateFlowCallback implements FutureCallback<RpcResult<UpdateFlowOutput>> {
+        private final UpdateFlowInput input;
+
+        private UpdateFlowCallback(UpdateFlowInput input) {
+            this.input = input;
+        }
+
+        @Override
+        public void onSuccess(final RpcResult<UpdateFlowOutput> o) {
+            final UpdatedFlow updated = input.getUpdatedFlow();
+            final OriginalFlow original = input.getOriginalFlow();
+            FlowRegistryKey flowRegistryKey = FlowRegistryKeyFactory.create(original);
+
+            FlowRegistryKey updatedflowRegistryKey = FlowRegistryKeyFactory.create(updated);
+            final FlowRef flowRef = input.getFlowRef();
+            final DeviceFlowRegistry deviceFlowRegistry = deviceContext.getDeviceFlowRegistry();
+
+            if (flowRef == null) {
+                // then this is equivalent to a delete
+                deviceFlowRegistry.markToBeremoved(flowRegistryKey);
+
+                if (itemLifecycleListener != null) {
+                    final FlowDescriptor flowDescriptor =
+                            deviceContext.getDeviceFlowRegistry().retrieveIdForFlow( flowRegistryKey);
+                    KeyedInstanceIdentifier<Flow, FlowKey> flowPath = createFlowPath(flowDescriptor,
+                            deviceContext.getDeviceInfo().getNodeInstanceIdentifier());
+                    itemLifecycleListener.onRemoved(flowPath);
+                }
+            } else {
+                // this is either an add or an update
+                final FlowId flowId = flowRef.getValue().firstKeyOf(Flow.class, FlowKey.class).getId();
+                final FlowDescriptor flowDescriptor = FlowDescriptorFactory.create(updated.getTableId(), flowId);
+                deviceFlowRegistry.store(updatedflowRegistryKey, flowDescriptor);
+
+                if (itemLifecycleListener != null) {
+                    KeyedInstanceIdentifier<Flow, FlowKey> flowPath = createFlowPath(flowDescriptor,
+                            deviceContext.getDeviceInfo().getNodeInstanceIdentifier());
+                    final FlowBuilder flowBuilder = new FlowBuilder(
+                            input.getUpdatedFlow()).setId(flowDescriptor.getFlowId());
+
+                    boolean isUpdate = null !=
+                            deviceFlowRegistry.retrieveIdForFlow(flowRegistryKey);
+                    if (isUpdate) {
+                        itemLifecycleListener.onUpdated(flowPath, flowBuilder.build());
+                    } else {
+                        itemLifecycleListener.onAdded(flowPath, flowBuilder.build());
+                    }
+                }
+            }
+        }
+
+        @Override
+        public void onFailure(final Throwable throwable) {
+            LOG.error("Service call for updating flow failed, reason{}", throwable);
+        }
     }
 }
\ No newline at end of file
index 86f9afe8e98174c068903c4db3aeca90ec5aed66..3fc621e356a990966b517c924df375876cd0a7b9 100644 (file)
@@ -40,7 +40,7 @@ public final class SalPortServiceImpl extends AbstractSimpleService<UpdatePortIn
     }
 
     @Override
-    protected OfHeader buildRequest(final Xid xid, final UpdatePortInput input) {
+    protected OfHeader buildRequest(final Xid xid, final UpdatePortInput input) throws ServiceException {
         final Port inputPort = input.getUpdatedPort().getPort().getPort().get(0);
         final Optional<PortModInput> ofPortModInput = convertorExecutor.convert(inputPort, data);
 
index e357397d09a13b0f8ef21d3f129b395f49b725c8..9906515af633106c39dd1f239c6e653ff2d35722 100644 (file)
@@ -58,7 +58,7 @@ public final class SalRoleServiceImpl extends AbstractSimpleService<SetRoleInput
     }
 
     @Override
-    protected OfHeader buildRequest(final Xid xid, final SetRoleInput input) {
+    protected OfHeader buildRequest(final Xid xid, final SetRoleInput input) throws ServiceException {
         return null;
     }
 
index 25ccd243ae49e1b9a44628d91b963349e881bd56..ef757c9c4f80bce02bd22f370d24f8e27193fd0d 100644 (file)
@@ -170,7 +170,7 @@ public final class SalTableServiceImpl extends AbstractMultipartService<UpdateTa
     }
 
     @Override
-    protected OfHeader buildRequest(final Xid xid, final UpdateTableInput input) {
+    protected OfHeader buildRequest(final Xid xid, final UpdateTableInput input) throws ServiceException {
         final MultipartRequestTableFeaturesCaseBuilder caseBuilder = new MultipartRequestTableFeaturesCaseBuilder();
         final MultipartRequestTableFeaturesBuilder requestBuilder = new MultipartRequestTableFeaturesBuilder();
 
diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/ServiceException.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/ServiceException.java
new file mode 100644 (file)
index 0000000..7804e0b
--- /dev/null
@@ -0,0 +1,18 @@
+/*
+ * Copyright (c) 2016 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.impl.services;
+
+/**
+ * Exception thrown by {@link org.opendaylight.openflowplugin.impl.services.AbstractService#buildRequest(org.opendaylight.openflowplugin.api.openflow.device.Xid, Object)}
+ */
+public class ServiceException extends Exception {
+    public ServiceException(Throwable cause) {
+        super(cause);
+    }
+}
index 80c9d42cfa5854435303737d7338918756d2d937..a09e0bf840db2f74418df465ea5ae9aa3a0a16bc 100644 (file)
@@ -13,6 +13,7 @@ import java.util.Collections;
 import java.util.List;
 import java.util.Optional;
 import org.opendaylight.openflowplugin.api.openflow.md.util.OpenflowVersion;
+import org.opendaylight.openflowplugin.impl.util.GroupUtil;
 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorExecutor;
 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.data.VersionDatapathIdConvertorData;
 import org.opendaylight.openflowplugin.openflow.md.util.InventoryDataServiceUtil;
@@ -341,7 +342,7 @@ public class SinglePurposeMultipartReplyTranslator {
 
         message.setGroupCapabilitiesSupported(supportedCapabilities);
 
-        message.setActions(getGroupActionsSupportBitmap(replyBody.getActionsBitmap()));
+        message.setActions(GroupUtil.extractGroupActionsSupportBitmap(replyBody.getActionsBitmap()));
         listDataObject.add(message.build());
     }
 
@@ -527,36 +528,4 @@ public class SinglePurposeMultipartReplyTranslator {
         BigInteger bigIntXid = BigInteger.valueOf(xid);
         return new TransactionId(bigIntXid);
     }
-
-    /*
-     * Method returns the bitmap of actions supported by each group.
-     *
-     * @param actionsSupported
-     * @return
-     */
-    static List<Long> getGroupActionsSupportBitmap(final List<org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.ActionType> actionsSupported) {
-        List<Long> supportActionByGroups = new ArrayList<Long>();
-        for (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.ActionType supportedActions : actionsSupported) {
-            long supportActionBitmap = 0;
-            supportActionBitmap |= supportedActions.isOFPATOUTPUT() ? (1 << 0) : 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(Long.valueOf(supportActionBitmap));
-        }
-        return supportActionByGroups;
-    }
-
 }
index 45a19e1ae56add3299a60952f6b4e908655757d1..5d8fa400d71cee9467a0f7cb627956ca89afe1e8 100644 (file)
@@ -18,6 +18,7 @@ import org.opendaylight.openflowplugin.api.openflow.device.TranslatorLibrary;
 import org.opendaylight.openflowplugin.api.openflow.device.Xid;
 import org.opendaylight.openflowplugin.api.openflow.md.core.TranslatorKey;
 import org.opendaylight.openflowplugin.impl.services.RequestInputUtils;
+import org.opendaylight.openflowplugin.impl.services.ServiceException;
 import org.opendaylight.openflowplugin.impl.statistics.services.compatibility.AbstractCompatibleStatService;
 import org.opendaylight.openflowplugin.openflow.md.util.FlowCreatorUtil;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.AggregateFlowStatisticsUpdate;
@@ -54,7 +55,7 @@ public final class AggregateFlowsInTableService extends AbstractCompatibleStatSe
     }
 
     @Override
-    protected OfHeader buildRequest(final Xid xid, final GetAggregateFlowStatisticsFromFlowTableForAllFlowsInput input) {
+    protected OfHeader buildRequest(final Xid xid, final GetAggregateFlowStatisticsFromFlowTableForAllFlowsInput input) throws ServiceException {
         // Create multipart request body for fetch all the group stats
         final MultipartRequestAggregateCaseBuilder multipartRequestAggregateCaseBuilder = new MultipartRequestAggregateCaseBuilder();
         final MultipartRequestAggregateBuilder mprAggregateRequestBuilder = new MultipartRequestAggregateBuilder();
index caa24be942bf1815b0351f75e5f3f0900c86b4e7..c466f1dde37cbbef8bb7981f716cc2dae517c368 100644 (file)
@@ -14,6 +14,7 @@ import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
 import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack;
 import org.opendaylight.openflowplugin.api.openflow.device.Xid;
 import org.opendaylight.openflowplugin.impl.services.RequestInputUtils;
+import org.opendaylight.openflowplugin.impl.services.ServiceException;
 import org.opendaylight.openflowplugin.impl.statistics.services.compatibility.AbstractCompatibleStatService;
 import org.opendaylight.openflowplugin.impl.statistics.services.compatibility.FlowStatisticsToNotificationTransformer;
 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorExecutor;
@@ -55,7 +56,7 @@ public final class AllFlowsInAllTablesService extends AbstractCompatibleStatServ
     }
 
     @Override
-    protected OfHeader buildRequest(final Xid xid, final GetAllFlowsStatisticsFromAllFlowTablesInput input) {
+    protected OfHeader buildRequest(final Xid xid, final GetAllFlowsStatisticsFromAllFlowTablesInput input) throws ServiceException {
         final MultipartRequestInputBuilder mprInput = RequestInputUtils.createMultipartHeader(
                 MultipartType.OFPMPFLOW, xid.getValue(), getVersion());
         mprInput.setMultipartRequestBody(flowCase);
index d7a4af5da35782cbb5dfb4c6c5dcf9b38b5cc39a..d37a31dc8c0a505f56e776861473181fbe6d0647 100644 (file)
@@ -15,6 +15,7 @@ import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
 import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack;
 import org.opendaylight.openflowplugin.api.openflow.device.Xid;
 import org.opendaylight.openflowplugin.impl.services.RequestInputUtils;
+import org.opendaylight.openflowplugin.impl.services.ServiceException;
 import org.opendaylight.openflowplugin.impl.statistics.services.compatibility.AbstractCompatibleStatService;
 import org.opendaylight.openflowplugin.impl.statistics.services.compatibility.FlowStatisticsToNotificationTransformer;
 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorExecutor;
@@ -44,7 +45,7 @@ public class AllFlowsInTableService extends AbstractCompatibleStatService<GetAll
     }
 
     @Override
-    protected OfHeader buildRequest(final Xid xid, final GetAllFlowStatisticsFromFlowTableInput input) {
+    protected OfHeader buildRequest(final Xid xid, final GetAllFlowStatisticsFromFlowTableInput input) throws ServiceException {
         final MultipartRequestFlowBuilder mprFlowRequestBuilder = new MultipartRequestFlowBuilder();
         mprFlowRequestBuilder.setTableId(input.getTableId().getValue());
         mprFlowRequestBuilder.setOutPort(OFConstants.OFPP_ANY);
index 4c563dde03196afba06de62ea70049daa8863dfe..55e3368ddf5ca40c1978969c9303c19f3ab24ed6 100644 (file)
@@ -14,6 +14,7 @@ import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
 import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack;
 import org.opendaylight.openflowplugin.api.openflow.device.Xid;
 import org.opendaylight.openflowplugin.impl.services.RequestInputUtils;
+import org.opendaylight.openflowplugin.impl.services.ServiceException;
 import org.opendaylight.openflowplugin.impl.statistics.services.compatibility.AbstractCompatibleStatService;
 import org.opendaylight.openflowplugin.impl.statistics.services.compatibility.GroupStatisticsToNotificationTransformer;
 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorExecutor;
@@ -56,7 +57,7 @@ final class AllGroupsStatsService extends
 
 
     @Override
-    protected OfHeader buildRequest(final Xid xid, final GetAllGroupStatisticsInput input) {
+    protected OfHeader buildRequest(final Xid xid, final GetAllGroupStatisticsInput input) throws ServiceException {
         // Create multipart request header
         final MultipartRequestInputBuilder mprInput = RequestInputUtils.createMultipartHeader(
                 MultipartType.OFPMPGROUP, xid.getValue(), getVersion());
index 19768808addff4e38b2a971e62894b6599adcb73..bb72f11925cf4ba1b25d31c7b0a2c08b53d1f421 100644 (file)
@@ -16,6 +16,7 @@ import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
 import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack;
 import org.opendaylight.openflowplugin.api.openflow.device.Xid;
 import org.opendaylight.openflowplugin.impl.services.RequestInputUtils;
+import org.opendaylight.openflowplugin.impl.services.ServiceException;
 import org.opendaylight.openflowplugin.impl.statistics.services.compatibility.AbstractCompatibleStatService;
 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorExecutor;
 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.data.VersionConvertorData;
@@ -65,7 +66,7 @@ final class AllMeterConfigStatsService
     }
 
     @Override
-    protected OfHeader buildRequest(final Xid xid, final GetAllMeterConfigStatisticsInput input) {
+    protected OfHeader buildRequest(final Xid xid, final GetAllMeterConfigStatisticsInput input) throws ServiceException {
         MultipartRequestInputBuilder mprInput = RequestInputUtils
                 .createMultipartHeader(MultipartType.OFPMPMETERCONFIG, xid.getValue(), getVersion());
         return mprInput.setMultipartRequestBody(METER_CONFIG_CASE).build();
index 2c47f1ec58c6109ef97eb8f6eab2042db9a16c7e..ef80529f9c7addbc4b55354de4a2aab01cb37eb4 100644 (file)
@@ -14,6 +14,7 @@ import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
 import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack;
 import org.opendaylight.openflowplugin.api.openflow.device.Xid;
 import org.opendaylight.openflowplugin.impl.services.RequestInputUtils;
+import org.opendaylight.openflowplugin.impl.services.ServiceException;
 import org.opendaylight.openflowplugin.impl.statistics.services.compatibility.AbstractCompatibleStatService;
 import org.opendaylight.openflowplugin.impl.statistics.services.compatibility.MeterStatisticsToNotificationTransformer;
 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorExecutor;
@@ -55,7 +56,7 @@ final class AllMeterStatsService
     }
 
     @Override
-    protected OfHeader buildRequest(final Xid xid, final GetAllMeterStatisticsInput input) {
+    protected OfHeader buildRequest(final Xid xid, final GetAllMeterStatisticsInput input) throws ServiceException {
         MultipartRequestInputBuilder mprInput = RequestInputUtils
                 .createMultipartHeader(MultipartType.OFPMPMETER, xid.getValue(), getVersion());
         return mprInput.setMultipartRequestBody(METER_CASE).build();
index 20be7f9433deefcd7e451bcc20a8e34e54089687..393dc43b95770831a678a663162048110ea60cd4 100644 (file)
@@ -14,6 +14,7 @@ import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
 import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack;
 import org.opendaylight.openflowplugin.api.openflow.device.Xid;
 import org.opendaylight.openflowplugin.impl.services.RequestInputUtils;
+import org.opendaylight.openflowplugin.impl.services.ServiceException;
 import org.opendaylight.openflowplugin.impl.statistics.services.compatibility.AbstractCompatibleStatService;
 import org.opendaylight.openflowplugin.impl.statistics.services.compatibility.NodeConnectorStatisticsToNotificationTransformer;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.transaction.rev150304.TransactionId;
@@ -51,7 +52,7 @@ final class AllPortStatsService
     }
 
     @Override
-    protected OfHeader buildRequest(final Xid xid, final GetAllNodeConnectorsStatisticsInput input) {
+    protected OfHeader buildRequest(final Xid xid, final GetAllNodeConnectorsStatisticsInput input) throws ServiceException {
         MultipartRequestInputBuilder mprInput = RequestInputUtils
                 .createMultipartHeader(MultipartType.OFPMPPORTSTATS, xid.getValue(), getVersion());
         mprInput.setMultipartRequestBody(PORT_STATS_CASE);
index ca34feb4c5dbecbcaf51ad09652ef1c176269564..054a99ac36cd77121ac77774005f9c2895afeb7b 100644 (file)
@@ -14,6 +14,7 @@ import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
 import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack;
 import org.opendaylight.openflowplugin.api.openflow.device.Xid;
 import org.opendaylight.openflowplugin.impl.services.RequestInputUtils;
+import org.opendaylight.openflowplugin.impl.services.ServiceException;
 import org.opendaylight.openflowplugin.impl.statistics.services.compatibility.AbstractCompatibleStatService;
 import org.opendaylight.openflowplugin.impl.statistics.services.compatibility.QueueStatisticsToNotificationTransformer;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.transaction.rev150304.TransactionId;
@@ -51,7 +52,7 @@ final class AllQueuesAllPortsService
     }
 
     @Override
-    protected OfHeader buildRequest(final Xid xid, final GetAllQueuesStatisticsFromAllPortsInput input) {
+    protected OfHeader buildRequest(final Xid xid, final GetAllQueuesStatisticsFromAllPortsInput input) throws ServiceException {
         // Set request body to main multipart request
         MultipartRequestInputBuilder mprInput = RequestInputUtils.createMultipartHeader(
                 MultipartType.OFPMPQUEUE, xid.getValue(), getVersion());
index 697edecaa01525037769cc80bf430cd323ac8ec7..0372c699f822fd734724279a1969e7ab7c74730a 100644 (file)
@@ -15,6 +15,7 @@ import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack;
 import org.opendaylight.openflowplugin.api.openflow.device.Xid;
 import org.opendaylight.openflowplugin.api.openflow.md.util.OpenflowVersion;
 import org.opendaylight.openflowplugin.impl.services.RequestInputUtils;
+import org.opendaylight.openflowplugin.impl.services.ServiceException;
 import org.opendaylight.openflowplugin.impl.statistics.services.compatibility.AbstractCompatibleStatService;
 import org.opendaylight.openflowplugin.impl.statistics.services.compatibility.QueueStatisticsToNotificationTransformer;
 import org.opendaylight.openflowplugin.openflow.md.util.InventoryDataServiceUtil;
@@ -38,7 +39,7 @@ final class AllQueuesOnePortService
     }
 
     @Override
-    protected OfHeader buildRequest(final Xid xid, final GetAllQueuesStatisticsFromGivenPortInput input) {
+    protected OfHeader buildRequest(final Xid xid, final GetAllQueuesStatisticsFromGivenPortInput input) throws ServiceException {
         MultipartRequestQueueCaseBuilder caseBuilder = new MultipartRequestQueueCaseBuilder();
         MultipartRequestQueueBuilder mprQueueBuilder = new MultipartRequestQueueBuilder();
         // Select all queues
index 1bf30f6650d1106f00bc9e61c0ce7bc745db437a..58f5c45df8f43350a9fd8dbe9a13ce29b6268e32 100644 (file)
@@ -14,6 +14,7 @@ import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
 import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack;
 import org.opendaylight.openflowplugin.api.openflow.device.Xid;
 import org.opendaylight.openflowplugin.impl.services.RequestInputUtils;
+import org.opendaylight.openflowplugin.impl.services.ServiceException;
 import org.opendaylight.openflowplugin.impl.statistics.services.compatibility.AbstractCompatibleStatService;
 import org.opendaylight.openflowplugin.impl.statistics.services.compatibility.FlowStatisticsToNotificationTransformer;
 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorExecutor;
@@ -41,7 +42,7 @@ public final class FlowsInTableService extends AbstractCompatibleStatService<Get
     }
 
     @Override
-    protected OfHeader buildRequest(final Xid xid, final GetFlowStatisticsFromFlowTableInput input) {
+    protected OfHeader buildRequest(final Xid xid, final GetFlowStatisticsFromFlowTableInput input) throws ServiceException {
         final MultipartRequestFlowCaseBuilder multipartRequestFlowCaseBuilder = new MultipartRequestFlowCaseBuilder();
         final MultipartRequestFlowBuilder mprFlowRequestBuilder = new MultipartRequestFlowBuilder();
 
index 1858309ae3298e7ac7d71694c2c842fed900347b..2e6ca05a69debca42c280f22f6c1f7710ae119de 100644 (file)
@@ -15,6 +15,7 @@ import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
 import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack;
 import org.opendaylight.openflowplugin.api.openflow.device.Xid;
 import org.opendaylight.openflowplugin.impl.services.RequestInputUtils;
+import org.opendaylight.openflowplugin.impl.services.ServiceException;
 import org.opendaylight.openflowplugin.impl.statistics.services.compatibility.AbstractCompatibleStatService;
 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorExecutor;
 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.data.VersionConvertorData;
@@ -45,7 +46,7 @@ final class GroupDescriptionService
     }
 
     @Override
-    protected OfHeader buildRequest(final Xid xid, final GetGroupDescriptionInput input) {
+    protected OfHeader buildRequest(final Xid xid, final GetGroupDescriptionInput input) throws ServiceException {
         final MultipartRequestInputBuilder mprInput = RequestInputUtils.createMultipartHeader(
                 MultipartType.OFPMPGROUPDESC, xid.getValue(), getVersion());
         mprInput.setMultipartRequestBody(GROUP_DESC_CASE);
index 008429797eff41b0cb774dee8f2cc4c7cc71face..80dfc7bb8b17b34182be4ca1b83979a1bb016f53 100644 (file)
@@ -16,7 +16,9 @@ import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
 import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack;
 import org.opendaylight.openflowplugin.api.openflow.device.Xid;
 import org.opendaylight.openflowplugin.impl.services.RequestInputUtils;
+import org.opendaylight.openflowplugin.impl.services.ServiceException;
 import org.opendaylight.openflowplugin.impl.statistics.services.compatibility.AbstractCompatibleStatService;
+import org.opendaylight.openflowplugin.impl.util.GroupUtil;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.transaction.rev150304.TransactionId;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetGroupFeaturesInput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetGroupFeaturesOutput;
@@ -33,7 +35,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.Group
 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.GroupType;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.SelectLiveness;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.SelectWeight;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.ActionType;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.GroupCapabilities;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.GroupTypes;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartType;
@@ -56,7 +57,7 @@ final class GroupFeaturesService
     }
 
     @Override
-    protected OfHeader buildRequest(final Xid xid, final GetGroupFeaturesInput input) {
+    protected OfHeader buildRequest(final Xid xid, final GetGroupFeaturesInput input) throws ServiceException {
         final MultipartRequestInputBuilder mprInput = RequestInputUtils.createMultipartHeader(
                 MultipartType.OFPMPGROUPFEATURES, xid.getValue(), getVersion());
         mprInput.setMultipartRequestBody(GROUP_FEAT_CASE);
@@ -84,7 +85,7 @@ final class GroupFeaturesService
         notification.setGroupTypesSupported(extractSupportedGroupTypes(replyBody.getTypes()));
         notification.setMaxGroups(replyBody.getMaxGroups());
         notification.setGroupCapabilitiesSupported(extractSupportedCapabilities(replyBody.getCapabilities()));
-        notification.setActions(extractGroupActionsSupportBitmap(replyBody.getActionsBitmap()));
+        notification.setActions(GroupUtil.extractGroupActionsSupportBitmap(replyBody.getActionsBitmap()));
 
         return notification.build();
     }
@@ -126,30 +127,4 @@ final class GroupFeaturesService
         }
         return supportedGroups;
     }
-
-    @VisibleForTesting
-    static List<Long> extractGroupActionsSupportBitmap(final List<ActionType> actionsSupported) {
-        List<Long> supportActionByGroups = new ArrayList<>();
-        for (ActionType supportedActions : actionsSupported) {
-            long supportActionBitmap = 0;
-            supportActionBitmap |= supportedActions.isOFPATOUTPUT() ? (1 << 0) : 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(Long.valueOf(supportActionBitmap));
-        }
-        return supportActionByGroups;
-    }
 }
index edb78d16ce31c3a2fdf82cdbd0a659adc3e711ec..ce95e5f75e0fb9246a044cc9e819a6c4f63eafea 100644 (file)
@@ -13,6 +13,7 @@ import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
 import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack;
 import org.opendaylight.openflowplugin.api.openflow.device.Xid;
 import org.opendaylight.openflowplugin.impl.services.RequestInputUtils;
+import org.opendaylight.openflowplugin.impl.services.ServiceException;
 import org.opendaylight.openflowplugin.impl.statistics.services.compatibility.AbstractCompatibleStatService;
 import org.opendaylight.openflowplugin.impl.statistics.services.compatibility.GroupStatisticsToNotificationTransformer;
 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorExecutor;
@@ -40,7 +41,7 @@ final class GroupStatsService
     }
 
     @Override
-    protected OfHeader buildRequest(final Xid xid, final GetGroupStatisticsInput input) {
+    protected OfHeader buildRequest(final Xid xid, final GetGroupStatisticsInput input) throws ServiceException {
         final MultipartRequestGroupCaseBuilder caseBuilder = new MultipartRequestGroupCaseBuilder();
         final MultipartRequestGroupBuilder mprGroupBuild = new MultipartRequestGroupBuilder();
         mprGroupBuild.setGroupId(new GroupId(input.getGroupId().getValue()));
index 5e013172047008dabc9cb64c02043388ff3f2a9d..1a6ba9c00c0a17b547b04d2174d54fe2e4e0432c 100644 (file)
@@ -15,6 +15,7 @@ import org.opendaylight.openflowplugin.api.openflow.device.Xid;
 import org.opendaylight.openflowplugin.impl.services.AbstractMultipartService;
 import org.opendaylight.openflowplugin.impl.services.RequestInputUtils;
 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorExecutor;
+import org.opendaylight.openflowplugin.impl.services.ServiceException;
 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.match.MatchReactor;
 import org.opendaylight.openflowplugin.openflow.md.util.FlowCreatorUtil;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAggregateFlowStatisticsFromFlowTableForGivenMatchInput;
@@ -34,7 +35,7 @@ final class MatchingFlowsInTableService extends AbstractMultipartService<GetAggr
     }
 
     @Override
-    protected OfHeader buildRequest(final Xid xid, final GetAggregateFlowStatisticsFromFlowTableForGivenMatchInput input) {
+    protected OfHeader buildRequest(final Xid xid, final GetAggregateFlowStatisticsFromFlowTableForGivenMatchInput input) throws ServiceException {
         final MultipartRequestAggregateCaseBuilder multipartRequestAggregateCaseBuilder = new MultipartRequestAggregateCaseBuilder();
         final MultipartRequestAggregateBuilder mprAggregateRequestBuilder = new MultipartRequestAggregateBuilder();
         final short tableId = MoreObjects.firstNonNull(input.getTableId(), OFConstants.OFPTT_ALL).shortValue();
index 5409a641366a80ec3d750daba289e46a36e73025..cd97a7364b39d126be87c11cd65c62d6e527b22d 100644 (file)
@@ -16,6 +16,7 @@ import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
 import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack;
 import org.opendaylight.openflowplugin.api.openflow.device.Xid;
 import org.opendaylight.openflowplugin.impl.services.RequestInputUtils;
+import org.opendaylight.openflowplugin.impl.services.ServiceException;
 import org.opendaylight.openflowplugin.impl.statistics.services.compatibility.AbstractCompatibleStatService;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Counter32;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.transaction.rev150304.TransactionId;
@@ -52,7 +53,7 @@ final class MeterFeaturesService
     }
 
     @Override
-    protected OfHeader buildRequest(final Xid xid, final GetMeterFeaturesInput input) {
+    protected OfHeader buildRequest(final Xid xid, final GetMeterFeaturesInput input) throws ServiceException {
         MultipartRequestInputBuilder mprInput =
                 RequestInputUtils.createMultipartHeader(MultipartType.OFPMPMETERFEATURES, xid.getValue(), getVersion());
         mprInput.setMultipartRequestBody(METER_FEATURES_CASE);
index d7c0ec0209bc29cb66467cb3c5ebf9937826e82a..2a0b96969f9e196f38d94f2319f2fc2a23427f6f 100644 (file)
@@ -13,6 +13,7 @@ import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
 import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack;
 import org.opendaylight.openflowplugin.api.openflow.device.Xid;
 import org.opendaylight.openflowplugin.impl.services.RequestInputUtils;
+import org.opendaylight.openflowplugin.impl.services.ServiceException;
 import org.opendaylight.openflowplugin.impl.statistics.services.compatibility.AbstractCompatibleStatService;
 import org.opendaylight.openflowplugin.impl.statistics.services.compatibility.MeterStatisticsToNotificationTransformer;
 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorExecutor;
@@ -40,7 +41,7 @@ final class MeterStatsService
     }
 
     @Override
-    protected OfHeader buildRequest(final Xid xid, final GetMeterStatisticsInput input) {
+    protected OfHeader buildRequest(final Xid xid, final GetMeterStatisticsInput input) throws ServiceException {
         MultipartRequestMeterCaseBuilder caseBuilder =
                 new MultipartRequestMeterCaseBuilder();
         MultipartRequestMeterBuilder mprMeterBuild =
index 469c91362e5dabba9e1a9763a0b987c6a1e63610..12ebb39efc4f8165ebdbd0551bcce7712f7c9471 100644 (file)
@@ -14,6 +14,7 @@ import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack;
 import org.opendaylight.openflowplugin.api.openflow.device.Xid;
 import org.opendaylight.openflowplugin.api.openflow.md.util.OpenflowVersion;
 import org.opendaylight.openflowplugin.impl.services.RequestInputUtils;
+import org.opendaylight.openflowplugin.impl.services.ServiceException;
 import org.opendaylight.openflowplugin.impl.statistics.services.compatibility.AbstractCompatibleStatService;
 import org.opendaylight.openflowplugin.impl.statistics.services.compatibility.QueueStatisticsToNotificationTransformer;
 import org.opendaylight.openflowplugin.openflow.md.util.InventoryDataServiceUtil;
@@ -37,7 +38,7 @@ final class OneQueueOnePortService
     }
 
     @Override
-    protected OfHeader buildRequest(final Xid xid, final GetQueueStatisticsFromGivenPortInput input) {
+    protected OfHeader buildRequest(final Xid xid, final GetQueueStatisticsFromGivenPortInput input) throws ServiceException {
         MultipartRequestQueueCaseBuilder caseBuilder = new MultipartRequestQueueCaseBuilder();
         MultipartRequestQueueBuilder mprQueueBuilder = new MultipartRequestQueueBuilder();
         // Select specific queue
index 326e6f7d55ff2992ef2a42a3b439fd64a9be8f33..efc8e6fcb2e61e3c84c7c4373d50bd26c9431ab1 100644 (file)
@@ -16,6 +16,7 @@ import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
 import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack;
 import org.opendaylight.openflowplugin.api.openflow.device.Xid;
 import org.opendaylight.openflowplugin.impl.services.RequestInputUtils;
+import org.opendaylight.openflowplugin.impl.services.ServiceException;
 import org.opendaylight.openflowplugin.impl.statistics.services.compatibility.AbstractCompatibleStatService;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Counter32;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Counter64;
@@ -61,7 +62,7 @@ public final class OpendaylightFlowTableStatisticsServiceImpl extends
     }
 
     @Override
-    protected OfHeader buildRequest(final Xid xid, final GetFlowTablesStatisticsInput input) {
+    protected OfHeader buildRequest(final Xid xid, final GetFlowTablesStatisticsInput input) throws ServiceException {
         // Create multipart request body for fetch all the group stats
         final MultipartRequestTableCaseBuilder multipartRequestTableCaseBuilder = new MultipartRequestTableCaseBuilder();
         final MultipartRequestTableBuilder multipartRequestTableBuilder = new MultipartRequestTableBuilder();
index 8354c3df762237e089208818159c10c9174fd617..8355c96e0da1d6bd94a2027f5cc71220efa536b5 100644 (file)
@@ -14,6 +14,7 @@ import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack;
 import org.opendaylight.openflowplugin.api.openflow.device.Xid;
 import org.opendaylight.openflowplugin.api.openflow.md.util.OpenflowVersion;
 import org.opendaylight.openflowplugin.impl.services.RequestInputUtils;
+import org.opendaylight.openflowplugin.impl.services.ServiceException;
 import org.opendaylight.openflowplugin.impl.statistics.services.compatibility.AbstractCompatibleStatService;
 import org.opendaylight.openflowplugin.impl.statistics.services.compatibility.NodeConnectorStatisticsToNotificationTransformer;
 import org.opendaylight.openflowplugin.openflow.md.util.InventoryDataServiceUtil;
@@ -37,7 +38,7 @@ final class PortStatsService
     }
 
     @Override
-    protected OfHeader buildRequest(final Xid xid, final GetNodeConnectorStatisticsInput input) {
+    protected OfHeader buildRequest(final Xid xid, final GetNodeConnectorStatisticsInput input) throws ServiceException {
         MultipartRequestPortStatsCaseBuilder caseBuilder =
                 new MultipartRequestPortStatsCaseBuilder();
         MultipartRequestPortStatsBuilder mprPortStatsBuilder =
index 3b4605959d78766195a3d083855f5ac4357c3906..0c8089f4bd2dd936cb4197577899fb3a2dba7507 100644 (file)
@@ -29,6 +29,11 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731
  * pulled out flow stats to notification transformation
  */
 public class FlowStatisticsToNotificationTransformer {
+
+    private FlowStatisticsToNotificationTransformer() {
+        // Hide implicit constructor
+    }
+
     /**
      * @param mpResult      raw multipart response from device
      * @param deviceInfo   device state
index 39bbfeb6d40193ec13ee6ddfc4cb47bd73153730..a0a842a12060e6aab11b1996279f6522faf74564 100644 (file)
@@ -26,6 +26,9 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731
  * pulled out group stats to notification transformation
  */
 public class GroupStatisticsToNotificationTransformer {
+    private GroupStatisticsToNotificationTransformer() {
+        // Hide implicit constructor
+    }
     /**
      * @param mpReplyList   raw multipart response from device
      * @param deviceInfo   device state
index 375fd6687274dbf033365bc1e3423ae3a1d1591a..ed84bf9355d0d90766113112645388d2ca0973eb 100644 (file)
@@ -28,6 +28,9 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731
  */
 public class MeterStatisticsToNotificationTransformer {
 
+    private MeterStatisticsToNotificationTransformer() {
+        // Hide implicit constructor
+    }
     /**
      * @param mpReplyList   raw multipart response from device
      * @param deviceInfo   device state
index e70d64bbc9c7d1c8698174b1929419b33efbec3a..d0eb39ce5ec9c99b943a5279162bf98fd1d2df09 100644 (file)
@@ -34,6 +34,10 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.n
  */
 public class NodeConnectorStatisticsToNotificationTransformer {
 
+    private NodeConnectorStatisticsToNotificationTransformer() {
+        // Hide implicit constructor
+    }
+
     /**
      * @param mpReplyList   raw multipart response from device
      * @param deviceInfo    device basic info
index 4fcb4afbd098798a0a95b03e3acbff568f1e5d96..1ba12e9d1cea5b63f31c60c15ab9bb474efb1497 100644 (file)
@@ -32,6 +32,10 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.
  */
 public class QueueStatisticsToNotificationTransformer {
 
+    private QueueStatisticsToNotificationTransformer() {
+        // Hide implicit constructor
+    }
+
     /**
      * @param mpReplyList   raw multipart response from device
      * @param deviceInfo   device state
index 1ba77a309bc04dfa0264a4c4df0dfdea41221875..a88e405b7c71372a3cb846253e2f7c52713c525f 100644 (file)
@@ -17,6 +17,7 @@ import org.opendaylight.openflowplugin.api.openflow.statistics.ofpspecific.Event
 import org.opendaylight.openflowplugin.api.openflow.statistics.ofpspecific.StatisticsGatherer;
 import org.opendaylight.openflowplugin.impl.common.MultipartRequestInputFactory;
 import org.opendaylight.openflowplugin.impl.services.AbstractMultipartOnTheFlyService;
+import org.opendaylight.openflowplugin.impl.services.ServiceException;
 import org.opendaylight.openflowplugin.impl.statistics.ofpspecific.EventsTimeCounter;
 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorExecutor;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartType;
@@ -46,7 +47,7 @@ public class StatisticsGatheringOnTheFlyService extends AbstractMultipartOnTheFl
     }
 
     @Override
-    protected OfHeader buildRequest(final Xid xid, final MultipartType input) {
+    protected OfHeader buildRequest(final Xid xid, final MultipartType input) throws ServiceException {
         return MultipartRequestInputFactory.makeMultipartRequestInput(xid.getValue(), getVersion(), input);
     }
 }
index b6f1b10f33c0c102ac85f5741d45a40616fc6e43..fc0f8d3f3ff3c09a6833ddc9efdab0eeb556be47 100644 (file)
@@ -17,6 +17,7 @@ import org.opendaylight.openflowplugin.api.openflow.statistics.ofpspecific.Event
 import org.opendaylight.openflowplugin.api.openflow.statistics.ofpspecific.StatisticsGatherer;
 import org.opendaylight.openflowplugin.impl.common.MultipartRequestInputFactory;
 import org.opendaylight.openflowplugin.impl.services.AbstractMultipartService;
+import org.opendaylight.openflowplugin.impl.services.ServiceException;
 import org.opendaylight.openflowplugin.impl.statistics.ofpspecific.EventsTimeCounter;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartType;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReply;
@@ -45,7 +46,7 @@ public class StatisticsGatheringService extends AbstractMultipartService<Multipa
     }
 
     @Override
-    protected OfHeader buildRequest(final Xid xid, final MultipartType input) {
+    protected OfHeader buildRequest(final Xid xid, final MultipartType input) throws ServiceException {
         return MultipartRequestInputFactory.makeMultipartRequestInput(xid.getValue(), getVersion(), input);
     }
 }
index 156c34a0cdefab96376ef45eca564ceb75084fb0..d8ad2ae86b3e47b65709ffe78e0720e12424a9e6 100644 (file)
@@ -23,6 +23,7 @@ import org.opendaylight.openflowplugin.api.openflow.md.util.OpenflowVersion;
 import org.opendaylight.openflowplugin.impl.services.AbstractMultipartService;
 import org.opendaylight.openflowplugin.impl.services.RequestInputUtils;
 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorExecutor;
+import org.opendaylight.openflowplugin.impl.services.ServiceException;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.direct.statistics.rev160511.StoreStatsGrouping;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartType;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReply;
@@ -107,7 +108,7 @@ public abstract class AbstractDirectStatisticsService<I extends StoreStatsGroupi
     }
 
     @Override
-    protected OfHeader buildRequest(Xid xid, I input) throws Exception {
+    protected OfHeader buildRequest(Xid xid, I input) throws ServiceException {
         return RequestInputUtils.createMultipartHeader(multipartType, xid.getValue(), getVersion())
                 .setMultipartRequestBody(buildRequestBody(input))
                 .build();
index bd40f4c9f6e9a436549be66c89cbec0be738f3a4..264f0d4d52e5766c3faf1356dc6bdf7ba5786554 100644 (file)
@@ -19,7 +19,6 @@ import java.net.InetSocketAddress;
 import java.util.Arrays;
 import java.util.Collection;
 import java.util.Collections;
-import java.util.Iterator;
 import java.util.List;
 import java.util.concurrent.ExecutionException;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
@@ -89,6 +88,10 @@ public class DeviceInitializationUtils {
 
     private static final Logger LOG = LoggerFactory.getLogger(DeviceInitializationUtils.class);
 
+    private DeviceInitializationUtils() {
+        // Hiding implicit constructor
+    }
+
     /**
      * InitializationNodeInformation is good to call only for MASTER otherwise we will have not empty transaction
      * for every Cluster Node (SLAVE too) and we will get race-condition by closing Connection.
@@ -230,106 +233,154 @@ public class DeviceInitializationUtils {
                                        final InstanceIdentifier<Node> nodeII, final Collection<MultipartReply> result,
                                        final ConvertorExecutor convertorExecutor) {
         try {
-            for (final MultipartReply reply : result) {
-                final MultipartReplyBody body = reply.getMultipartReplyBody();
-                switch (type) {
-                    case OFPMPDESC:
-                        Preconditions.checkArgument(body instanceof MultipartReplyDescCase);
-                        final MultipartReplyDesc replyDesc = ((MultipartReplyDescCase) body).getMultipartReplyDesc();
-                        final FlowCapableNode fcNode = NodeStaticReplyTranslatorUtil.nodeDescTranslator(replyDesc,
-                                getIpAddressOf(dContext));
-                        final InstanceIdentifier<FlowCapableNode> fNodeII = nodeII.augmentation(FlowCapableNode.class);
-                        dContext.writeToTransaction(LogicalDatastoreType.OPERATIONAL, fNodeII, fcNode);
-                        break;
-
-                    case OFPMPTABLEFEATURES:
-                        Preconditions.checkArgument(body instanceof MultipartReplyTableFeaturesCase);
-                        final MultipartReplyTableFeatures tableFeaturesMP = ((MultipartReplyTableFeaturesCase) body)
-                                .getMultipartReplyTableFeatures();
-                        final List<TableFeatures> tableFeatures = NodeStaticReplyTranslatorUtil
-                                .nodeTableFeatureTranslator(tableFeaturesMP, dContext.getDeviceInfo().getVersion(), convertorExecutor);
-                        for (final TableFeatures tableFeature : tableFeatures) {
-                            final Short tableId = tableFeature.getTableId();
-                            final KeyedInstanceIdentifier<TableFeatures, TableFeaturesKey> tableFeaturesII =
-                                    nodeII.augmentation(FlowCapableNode.class)
-                                            .child(TableFeatures.class, new TableFeaturesKey(tableId));
-                            dContext.writeToTransaction(LogicalDatastoreType.OPERATIONAL, tableFeaturesII, tableFeature);
-
-                            // write parent for table statistics
-                            final KeyedInstanceIdentifier<Table, TableKey> tableII =
-                                    nodeII.augmentation(FlowCapableNode.class)
-                                            .child(Table.class, new TableKey(tableId));
-                            final TableBuilder tableBld = new TableBuilder().setId(tableId)
-                                    .addAugmentation(FlowTableStatisticsData.class,
-                                            new FlowTableStatisticsDataBuilder().build());
-
-                            dContext.writeToTransaction(LogicalDatastoreType.OPERATIONAL, tableII, tableBld.build());
-                        }
-                        break;
-
-                    case OFPMPMETERFEATURES:
-                        Preconditions.checkArgument(body instanceof MultipartReplyMeterFeaturesCase);
-                        final MultipartReplyMeterFeatures meterFeatures = ((MultipartReplyMeterFeaturesCase) body)
-                                .getMultipartReplyMeterFeatures();
-                        final NodeMeterFeatures mFeature = NodeStaticReplyTranslatorUtil
-                                .nodeMeterFeatureTranslator(meterFeatures);
-                        final InstanceIdentifier<NodeMeterFeatures> mFeatureII = nodeII
-                                .augmentation(NodeMeterFeatures.class);
-                        dContext.writeToTransaction(LogicalDatastoreType.OPERATIONAL, mFeatureII, mFeature);
-                        if (0L < mFeature.getMeterFeatures().getMaxMeter().getValue()) {
-                            dContext.getDeviceState().setMeterAvailable(true);
+            result.stream()
+                    .map(MultipartReply::getMultipartReplyBody)
+                    .forEach(multipartReplyBody -> {
+                        if (!(writeDesc(type, multipartReplyBody, dContext, nodeII)
+                                || writeTableFeatures(type, multipartReplyBody, dContext, nodeII, convertorExecutor)
+                                || writeMeterFeatures(type, multipartReplyBody, dContext, nodeII)
+                                || writeGroupFeatures(type, multipartReplyBody, dContext, nodeII)
+                                || writePortDesc(type, multipartReplyBody, dContext, nodeII))) {
+                            throw new IllegalArgumentException("Unexpected MultipartType " + type);
                         }
-                        break;
-
-                    case OFPMPGROUPFEATURES:
-                        Preconditions.checkArgument(body instanceof MultipartReplyGroupFeaturesCase);
-                        final MultipartReplyGroupFeatures groupFeatures = ((MultipartReplyGroupFeaturesCase) body)
-                                .getMultipartReplyGroupFeatures();
-                        final NodeGroupFeatures gFeature = NodeStaticReplyTranslatorUtil
-                                .nodeGroupFeatureTranslator(groupFeatures);
-                        final InstanceIdentifier<NodeGroupFeatures> gFeatureII = nodeII
-                                .augmentation(NodeGroupFeatures.class);
-                        dContext.writeToTransaction(LogicalDatastoreType.OPERATIONAL, gFeatureII, gFeature);
-                        break;
-
-                    case OFPMPPORTDESC:
-                        Preconditions.checkArgument(body instanceof MultipartReplyPortDescCase);
-                        final MultipartReplyPortDesc portDesc = ((MultipartReplyPortDescCase) body)
-                                .getMultipartReplyPortDesc();
-                        for (final PortGrouping port : portDesc.getPorts()) {
-                            final short ofVersion = dContext.getDeviceInfo().getVersion();
-                            final TranslatorKey translatorKey = new TranslatorKey(ofVersion, PortGrouping.class.getName());
-                            final MessageTranslator<PortGrouping, FlowCapableNodeConnector> translator = dContext.oook()
-                                    .lookupTranslator(translatorKey);
-                            final FlowCapableNodeConnector fcNodeConnector = translator.translate(port, dContext.getDeviceInfo(), null);
-
-                            final BigInteger dataPathId = dContext.getPrimaryConnectionContext().getFeatures()
-                                    .getDatapathId();
-                            final NodeConnectorId nodeConnectorId = NodeStaticReplyTranslatorUtil.nodeConnectorId(
-                                    dataPathId.toString(), port.getPortNo(), ofVersion);
-                            final NodeConnectorBuilder ncBuilder = new NodeConnectorBuilder().setId(nodeConnectorId);
-                            ncBuilder.addAugmentation(FlowCapableNodeConnector.class, fcNodeConnector);
-
-                            ncBuilder.addAugmentation(FlowCapableNodeConnectorStatisticsData.class,
-                                    new FlowCapableNodeConnectorStatisticsDataBuilder().build());
-                            final NodeConnector connector = ncBuilder.build();
-
-                            final InstanceIdentifier<NodeConnector> connectorII = nodeII.child(NodeConnector.class,
-                                    connector.getKey());
-                            dContext.writeToTransaction(LogicalDatastoreType.OPERATIONAL, connectorII, connector);
-                        }
-
-                        break;
-
-                    default:
-                        throw new IllegalArgumentException("Unnexpected MultipartType " + type);
-                }
-            }
+                    });
         } catch (final Exception e) {
             LOG.debug("translateAndWriteReply: Failed to write node {} to DS ", dContext.getDeviceInfo().getNodeId().toString(), e);
         }
     }
 
+    private static boolean writeDesc(final MultipartType type,
+                                     final MultipartReplyBody body,
+                                     final DeviceContext dContext,
+                                     final InstanceIdentifier<Node> nodeII) {
+        if (!MultipartType.OFPMPDESC.equals(type)) {
+            return false;
+        }
+
+        Preconditions.checkArgument(body instanceof MultipartReplyDescCase);
+        final MultipartReplyDesc replyDesc = ((MultipartReplyDescCase) body).getMultipartReplyDesc();
+        final FlowCapableNode fcNode = NodeStaticReplyTranslatorUtil.nodeDescTranslator(replyDesc,
+                getIpAddressOf(dContext));
+        final InstanceIdentifier<FlowCapableNode> fNodeII = nodeII.augmentation(FlowCapableNode.class);
+        dContext.writeToTransaction(LogicalDatastoreType.OPERATIONAL, fNodeII, fcNode);
+        return true;
+    }
+
+    private static boolean writeTableFeatures(final MultipartType type,
+                                              final MultipartReplyBody body,
+                                              final DeviceContext dContext,
+                                              final InstanceIdentifier<Node> nodeII,
+                                              final ConvertorExecutor convertorExecutor) {
+        if (!MultipartType.OFPMPTABLEFEATURES.equals(type)) {
+            return false;
+        }
+
+        Preconditions.checkArgument(body instanceof MultipartReplyTableFeaturesCase);
+        final MultipartReplyTableFeatures tableFeaturesMP = ((MultipartReplyTableFeaturesCase) body)
+                .getMultipartReplyTableFeatures();
+        final List<TableFeatures> tableFeatures = NodeStaticReplyTranslatorUtil
+                .nodeTableFeatureTranslator(tableFeaturesMP, dContext.getDeviceInfo().getVersion(), convertorExecutor);
+        for (final TableFeatures tableFeature : tableFeatures) {
+            final Short tableId = tableFeature.getTableId();
+            final KeyedInstanceIdentifier<TableFeatures, TableFeaturesKey> tableFeaturesII =
+                    nodeII.augmentation(FlowCapableNode.class)
+                            .child(TableFeatures.class, new TableFeaturesKey(tableId));
+            dContext.writeToTransaction(LogicalDatastoreType.OPERATIONAL, tableFeaturesII, tableFeature);
+
+            // write parent for table statistics
+            final KeyedInstanceIdentifier<Table, TableKey> tableII =
+                    nodeII.augmentation(FlowCapableNode.class)
+                            .child(Table.class, new TableKey(tableId));
+            final TableBuilder tableBld = new TableBuilder().setId(tableId)
+                    .addAugmentation(FlowTableStatisticsData.class,
+                            new FlowTableStatisticsDataBuilder().build());
+
+            dContext.writeToTransaction(LogicalDatastoreType.OPERATIONAL, tableII, tableBld.build());
+        }
+
+        return true;
+    }
+
+    private static boolean writeMeterFeatures(final MultipartType type,
+                                              final MultipartReplyBody body,
+                                              final DeviceContext dContext,
+                                              final InstanceIdentifier<Node> nodeII) {
+        if (!MultipartType.OFPMPMETERFEATURES.equals(type)) {
+            return false;
+        }
+
+        Preconditions.checkArgument(body instanceof MultipartReplyMeterFeaturesCase);
+        final MultipartReplyMeterFeatures meterFeatures = ((MultipartReplyMeterFeaturesCase) body)
+                .getMultipartReplyMeterFeatures();
+        final NodeMeterFeatures mFeature = NodeStaticReplyTranslatorUtil
+                .nodeMeterFeatureTranslator(meterFeatures);
+        final InstanceIdentifier<NodeMeterFeatures> mFeatureII = nodeII
+                .augmentation(NodeMeterFeatures.class);
+        dContext.writeToTransaction(LogicalDatastoreType.OPERATIONAL, mFeatureII, mFeature);
+        if (0L < mFeature.getMeterFeatures().getMaxMeter().getValue()) {
+            dContext.getDeviceState().setMeterAvailable(true);
+        }
+
+        return true;
+    }
+
+    private static boolean writeGroupFeatures(final MultipartType type,
+                                              final MultipartReplyBody body,
+                                              final DeviceContext dContext,
+                                              final InstanceIdentifier<Node> nodeII) {
+        if (!MultipartType.OFPMPGROUPFEATURES.equals(type)) {
+            return false;
+        }
+
+        Preconditions.checkArgument(body instanceof MultipartReplyGroupFeaturesCase);
+        final MultipartReplyGroupFeatures groupFeatures = ((MultipartReplyGroupFeaturesCase) body)
+                .getMultipartReplyGroupFeatures();
+        final NodeGroupFeatures gFeature = NodeStaticReplyTranslatorUtil
+                .nodeGroupFeatureTranslator(groupFeatures);
+        final InstanceIdentifier<NodeGroupFeatures> gFeatureII = nodeII
+                .augmentation(NodeGroupFeatures.class);
+        dContext.writeToTransaction(LogicalDatastoreType.OPERATIONAL, gFeatureII, gFeature);
+
+        return true;
+    }
+
+    private static boolean writePortDesc(final MultipartType type,
+                                         final MultipartReplyBody body,
+                                         final DeviceContext dContext,
+                                         final InstanceIdentifier<Node> nodeII) {
+        if (!MultipartType.OFPMPPORTDESC.equals(type)) {
+            return false;
+        }
+
+        Preconditions.checkArgument(body instanceof MultipartReplyPortDescCase);
+        final MultipartReplyPortDesc portDesc = ((MultipartReplyPortDescCase) body)
+                .getMultipartReplyPortDesc();
+        for (final PortGrouping port : portDesc.getPorts()) {
+            final short ofVersion = dContext.getDeviceInfo().getVersion();
+            final TranslatorKey translatorKey = new TranslatorKey(ofVersion, PortGrouping.class.getName());
+            final MessageTranslator<PortGrouping, FlowCapableNodeConnector> translator = dContext.oook()
+                    .lookupTranslator(translatorKey);
+            final FlowCapableNodeConnector fcNodeConnector = translator.translate(port, dContext.getDeviceInfo(), null);
+
+            final BigInteger dataPathId = dContext.getPrimaryConnectionContext().getFeatures()
+                    .getDatapathId();
+            final NodeConnectorId nodeConnectorId = NodeStaticReplyTranslatorUtil.nodeConnectorId(
+                    dataPathId.toString(), port.getPortNo(), ofVersion);
+            final NodeConnectorBuilder ncBuilder = new NodeConnectorBuilder().setId(nodeConnectorId);
+            ncBuilder.addAugmentation(FlowCapableNodeConnector.class, fcNodeConnector);
+
+            ncBuilder.addAugmentation(FlowCapableNodeConnectorStatisticsData.class,
+                    new FlowCapableNodeConnectorStatisticsDataBuilder().build());
+            final NodeConnector connector = ncBuilder.build();
+
+            final InstanceIdentifier<NodeConnector> connectorII = nodeII.child(NodeConnector.class,
+                    connector.getKey());
+            dContext.writeToTransaction(LogicalDatastoreType.OPERATIONAL, connectorII, connector);
+        }
+
+        return true;
+    }
+
     private static void createEmptyFlowCapableNodeInDs(final DeviceContext deviceContext) {
         final FlowCapableNodeBuilder flowCapableNodeBuilder = new FlowCapableNodeBuilder();
         final InstanceIdentifier<FlowCapableNode> fNodeII = deviceContext.getDeviceInfo().getNodeInstanceIdentifier()
@@ -388,9 +439,7 @@ public class DeviceInitializationUtils {
                     LOG.info("Static node {} info: {} collected", deviceContext.getDeviceInfo().getNodeId(), type);
                     translateAndWriteReply(type, deviceContext, nodeII, result, convertorExecutor);
                 } else {
-                    final Iterator<RpcError> rpcErrorIterator = rpcResult.getErrors().iterator();
-                    while (rpcErrorIterator.hasNext()) {
-                        final RpcError rpcError = rpcErrorIterator.next();
+                    for (RpcError rpcError : rpcResult.getErrors()) {
                         LOG.info("Failed to retrieve static node {} info: {}", type, rpcError.getMessage());
                         if (null != rpcError.getCause()) {
                             LOG.trace("Detailed error:", rpcError.getCause());
index 9850864e0d64412243b6afb5c30bed1336fdd0a7..e602eb2d42a411aa3f45402fa7d5d57b6852a0bb 100644 (file)
@@ -36,16 +36,12 @@ import org.opendaylight.yangtools.yang.binding.DataContainer;
 import org.opendaylight.yangtools.yang.common.RpcError;
 import org.opendaylight.yangtools.yang.common.RpcResult;
 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 
 /**
  * provides flat batch util methods
  */
 public final class FlatBatchUtil {
 
-    private static final Logger LOG = LoggerFactory.getLogger(FlatBatchUtil.class);
-
     private FlatBatchUtil() {
         throw new IllegalStateException("This class should not be instantiated.");
     }
@@ -67,31 +63,33 @@ public final class FlatBatchUtil {
 
     @VisibleForTesting
     static boolean decideBarrier(final EnumSet<BatchStepType> previousTypes, final BatchStepType type) {
-        final boolean needBarrier;
-        switch (type) {
-            case FLOW_ADD:
-            case FLOW_UPDATE:
-                needBarrier = previousTypes.contains(BatchStepType.GROUP_ADD)
-                        || previousTypes.contains(BatchStepType.METER_ADD);
-                break;
-            case GROUP_ADD:
-                needBarrier = previousTypes.contains(BatchStepType.GROUP_ADD)
-                        || previousTypes.contains(BatchStepType.GROUP_UPDATE);
-                break;
-            case GROUP_REMOVE:
-                needBarrier = previousTypes.contains(BatchStepType.FLOW_REMOVE)
-                        || previousTypes.contains(BatchStepType.FLOW_UPDATE)
-                        || previousTypes.contains(BatchStepType.GROUP_REMOVE)
-                        || previousTypes.contains(BatchStepType.GROUP_UPDATE);
-                break;
-            case METER_REMOVE:
-                needBarrier = previousTypes.contains(BatchStepType.FLOW_REMOVE)
-                        || previousTypes.contains(BatchStepType.FLOW_UPDATE);
-                break;
-            default:
-                needBarrier = false;
-        }
-        return needBarrier;
+        return isFlowBarrierNeeded(previousTypes, type)
+                || isGroupBarrierNeeded(previousTypes, type)
+                || isMeterBarrierNeeded(previousTypes, type);
+    }
+
+    private static boolean isFlowBarrierNeeded(final EnumSet<BatchStepType> previousTypes, final BatchStepType type) {
+        return (type == BatchStepType.FLOW_ADD
+                || type == BatchStepType.FLOW_UPDATE)
+                && (previousTypes.contains(BatchStepType.GROUP_ADD)
+                || previousTypes.contains(BatchStepType.METER_ADD));
+    }
+
+    private static boolean isGroupBarrierNeeded(final EnumSet<BatchStepType> previousTypes, final BatchStepType type) {
+        return (type == BatchStepType.GROUP_ADD
+                && (previousTypes.contains(BatchStepType.GROUP_ADD)
+                || previousTypes.contains(BatchStepType.GROUP_UPDATE)))
+                || (type == BatchStepType.GROUP_REMOVE
+                && (previousTypes.contains(BatchStepType.FLOW_REMOVE)
+                || previousTypes.contains(BatchStepType.FLOW_UPDATE)
+                || previousTypes.contains(BatchStepType.GROUP_REMOVE)
+                || previousTypes.contains(BatchStepType.GROUP_UPDATE)));
+    }
+
+    private static boolean isMeterBarrierNeeded(final EnumSet<BatchStepType> previousTypes, final BatchStepType type) {
+        return type == BatchStepType.METER_REMOVE
+                && (previousTypes.contains(BatchStepType.FLOW_REMOVE)
+                || previousTypes.contains(BatchStepType.FLOW_UPDATE));
     }
 
     public static List<BatchPlanStep> assembleBatchPlan(List<Batch> batches) {
index 2aad0ecc568cb8d21d3a723d4da58d424eb32b11..616256174bc1ac0d1d80a6abbf56ea426de61ce2 100644 (file)
@@ -41,11 +41,9 @@ 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.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 
 public final class FlowUtil {
-    private static final Logger LOG = LoggerFactory.getLogger(FlowUtil.class);
+
     private static final RpcResultBuilder<List<BatchFailedFlowsOutput>> SUCCESSFUL_FLOW_OUTPUT_RPC_RESULT =
             RpcResultBuilder.success(Collections.<BatchFailedFlowsOutput>emptyList());
 
@@ -206,43 +204,55 @@ public final class FlowUtil {
      */
     public static <O> Function<List<RpcResult<O>>, RpcResult<List<BatchFailedFlowsOutput>>> createCumulatingFunction(
             final List<? extends BatchFlowIdGrouping> inputBatchFlows) {
-        return new Function<List<RpcResult<O>>, RpcResult<List<BatchFailedFlowsOutput>>>() {
-            @Nullable
-            @Override
-            public RpcResult<List<BatchFailedFlowsOutput>> apply(@Nullable final List<RpcResult<O>> innerInput) {
-                final int sizeOfFutures = innerInput.size();
-                final int sizeOfInputBatch = inputBatchFlows.size();
-                Preconditions.checkArgument(sizeOfFutures == sizeOfInputBatch,
-                        "wrong amount of returned futures: {} <> {}", sizeOfFutures, sizeOfInputBatch);
-
-                final ArrayList<BatchFailedFlowsOutput> batchFlows = new ArrayList<>(sizeOfFutures);
-                final Iterator<? extends BatchFlowIdGrouping> batchFlowIterator = inputBatchFlows.iterator();
-
-                Collection<RpcError> flowErrors = new ArrayList<>(sizeOfFutures);
-
-                int batchOrder = 0;
-                for (RpcResult<O> flowModOutput : innerInput) {
-                    final FlowId flowId = batchFlowIterator.next().getFlowId();
-
-                    if (!flowModOutput.isSuccessful()) {
-                        batchFlows.add(new BatchFailedFlowsOutputBuilder()
-                                .setFlowId(flowId)
-                                .setBatchOrder(batchOrder)
-                                .build());
-                        flowErrors.addAll(flowModOutput.getErrors());
+        return new CumulatingFunction<O>(inputBatchFlows).invoke();
+    }
+
+    private static class CumulatingFunction<O> {
+        private final List<? extends BatchFlowIdGrouping> inputBatchFlows;
+
+        public CumulatingFunction(List<? extends BatchFlowIdGrouping> inputBatchFlows) {
+            this.inputBatchFlows = inputBatchFlows;
+        }
+
+        public Function<List<RpcResult<O>>, RpcResult<List<BatchFailedFlowsOutput>>> invoke() {
+            return new Function<List<RpcResult<O>>, RpcResult<List<BatchFailedFlowsOutput>>>() {
+                @Nullable
+                @Override
+                public RpcResult<List<BatchFailedFlowsOutput>> apply(@Nullable final List<RpcResult<O>> innerInput) {
+                    final int sizeOfFutures = innerInput.size();
+                    final int sizeOfInputBatch = inputBatchFlows.size();
+                    Preconditions.checkArgument(sizeOfFutures == sizeOfInputBatch,
+                            "wrong amount of returned futures: {} <> {}", sizeOfFutures, sizeOfInputBatch);
+
+                    final ArrayList<BatchFailedFlowsOutput> batchFlows = new ArrayList<>(sizeOfFutures);
+                    final Iterator<? extends BatchFlowIdGrouping> batchFlowIterator = inputBatchFlows.iterator();
+
+                    Collection<RpcError> flowErrors = new ArrayList<>(sizeOfFutures);
+
+                    int batchOrder = 0;
+                    for (RpcResult<O> flowModOutput : innerInput) {
+                        final FlowId flowId = batchFlowIterator.next().getFlowId();
+
+                        if (!flowModOutput.isSuccessful()) {
+                            batchFlows.add(new BatchFailedFlowsOutputBuilder()
+                                    .setFlowId(flowId)
+                                    .setBatchOrder(batchOrder)
+                                    .build());
+                            flowErrors.addAll(flowModOutput.getErrors());
+                        }
+                        batchOrder++;
                     }
-                    batchOrder++;
-                }
 
-                final RpcResultBuilder<List<BatchFailedFlowsOutput>> resultBuilder;
-                if (!flowErrors.isEmpty()) {
-                    resultBuilder = RpcResultBuilder.<List<BatchFailedFlowsOutput>>failed()
-                            .withRpcErrors(flowErrors).withResult(batchFlows);
-                } else {
-                    resultBuilder = SUCCESSFUL_FLOW_OUTPUT_RPC_RESULT;
+                    final RpcResultBuilder<List<BatchFailedFlowsOutput>> resultBuilder;
+                    if (!flowErrors.isEmpty()) {
+                        resultBuilder = RpcResultBuilder.<List<BatchFailedFlowsOutput>>failed()
+                                .withRpcErrors(flowErrors).withResult(batchFlows);
+                    } else {
+                        resultBuilder = SUCCESSFUL_FLOW_OUTPUT_RPC_RESULT;
+                    }
+                    return resultBuilder.build();
                 }
-                return resultBuilder.build();
-            }
-        };
+            };
+        }
     }
 }
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();
+                }
+            };
+        }
+    }
 }
index d224c702792fbec2c9abaee9a92c0c954a78ecb4..e31cafd51570baf341fe16d4b88b8b38be085309 100644 (file)
@@ -121,44 +121,7 @@ public final class MeterUtil {
     public static <O> Function<List<RpcResult<O>>, RpcResult<List<BatchFailedMetersOutput>>> createCumulativeFunction(
             final Iterable<? extends org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.Meter> inputBatchMeters,
             final int sizeOfInputBatch) {
-        return new Function<List<RpcResult<O>>, RpcResult<List<BatchFailedMetersOutput>>>() {
-            @Nullable
-            @Override
-            public RpcResult<List<BatchFailedMetersOutput>> 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<BatchFailedMetersOutput> batchMeters = new ArrayList<>();
-                final Iterator<? extends org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.Meter>
-                        batchMeterIterator = inputBatchMeters.iterator();
-
-                Collection<RpcError> meterErrors = new ArrayList<>(sizeOfFutures);
-
-                int batchOrder = 0;
-                for (RpcResult<O> meterModOutput : innerInput) {
-                    final MeterId meterId = batchMeterIterator.next().getMeterId();
-
-                    if (!meterModOutput.isSuccessful()) {
-                        batchMeters.add(new BatchFailedMetersOutputBuilder()
-                                .setBatchOrder(batchOrder)
-                                .setMeterId(meterId)
-                                .build());
-                        meterErrors.addAll(meterModOutput.getErrors());
-                    }
-                    batchOrder++;
-                }
-
-                final RpcResultBuilder<List<BatchFailedMetersOutput>> resultBuilder;
-                if (!meterErrors.isEmpty()) {
-                    resultBuilder = RpcResultBuilder.<List<BatchFailedMetersOutput>>failed()
-                            .withRpcErrors(meterErrors).withResult(batchMeters);
-                } else {
-                    resultBuilder = SUCCESSFUL_METER_OUTPUT_RPC_RESULT;
-                }
-                return resultBuilder.build();
-            }
-        };
+        return new CumulativeFunction<O>(inputBatchMeters, sizeOfInputBatch).invoke();
     }
 
     /**
@@ -216,4 +179,55 @@ public final class MeterUtil {
         }
         return resultBld;
     }
+
+    private static class CumulativeFunction<O> {
+        private final Iterable<? extends org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.Meter> inputBatchMeters;
+        private final int sizeOfInputBatch;
+
+        public CumulativeFunction(Iterable<? extends org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.Meter> inputBatchMeters, int sizeOfInputBatch) {
+            this.inputBatchMeters = inputBatchMeters;
+            this.sizeOfInputBatch = sizeOfInputBatch;
+        }
+
+        public Function<List<RpcResult<O>>, RpcResult<List<BatchFailedMetersOutput>>> invoke() {
+            return new Function<List<RpcResult<O>>, RpcResult<List<BatchFailedMetersOutput>>>() {
+                @Nullable
+                @Override
+                public RpcResult<List<BatchFailedMetersOutput>> 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<BatchFailedMetersOutput> batchMeters = new ArrayList<>();
+                    final Iterator<? extends org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.Meter>
+                            batchMeterIterator = inputBatchMeters.iterator();
+
+                    Collection<RpcError> meterErrors = new ArrayList<>(sizeOfFutures);
+
+                    int batchOrder = 0;
+                    for (RpcResult<O> meterModOutput : innerInput) {
+                        final MeterId meterId = batchMeterIterator.next().getMeterId();
+
+                        if (!meterModOutput.isSuccessful()) {
+                            batchMeters.add(new BatchFailedMetersOutputBuilder()
+                                    .setBatchOrder(batchOrder)
+                                    .setMeterId(meterId)
+                                    .build());
+                            meterErrors.addAll(meterModOutput.getErrors());
+                        }
+                        batchOrder++;
+                    }
+
+                    final RpcResultBuilder<List<BatchFailedMetersOutput>> resultBuilder;
+                    if (!meterErrors.isEmpty()) {
+                        resultBuilder = RpcResultBuilder.<List<BatchFailedMetersOutput>>failed()
+                                .withRpcErrors(meterErrors).withResult(batchMeters);
+                    } else {
+                        resultBuilder = SUCCESSFUL_METER_OUTPUT_RPC_RESULT;
+                    }
+                    return resultBuilder.build();
+                }
+            };
+        }
+    }
 }
index a8940cb58ff5bc26e6e86e3cd71e4a913d77d9cf..c0d55986fcd49a23ae3b2c7b6394603dd9eb4a43 100644 (file)
@@ -51,7 +51,7 @@ public class SalPortServiceImplTest extends ServiceMocking {
     }
 
     @Test
-    public void testBuildRequest() {
+    public void testBuildRequest() throws Exception {
         final OfHeader ofHeader = salPortService.buildRequest(new Xid(DUMMY_XID), dummyUpdatePortInput());
     }
 
index 3c1cabd8972489b47ac673a37ef8139b883a60f4..5ab810539ebbfdc55b2129595d0743495a88cc85 100644 (file)
@@ -32,7 +32,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.
 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.GroupTypes;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.desc.stats.reply.GroupDescStats;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Node;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.ActionType;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.GroupId;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.GroupType;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartRequestFlags;
@@ -87,7 +86,6 @@ public class SinglePurposeMultipartReplyTranslatorTest {
     private static final Long DUMMY_REF_COUNT = 1234L;
     private static final GroupTypes DUMMY_GROUPS_TYPE = GroupTypes.GroupAll;
     private static final GroupType DUMMY_GROUP_TYPE = GroupType.OFPGTALL;
-    private static final Long GROUP_ACTION_BITMAP = 0b00000000000000000000000000000000000001111111111111001100000000001L;
 
     @Before
     public void setUp() {
@@ -209,15 +207,6 @@ public class SinglePurposeMultipartReplyTranslatorTest {
         assertEquals(DUMMY_GROUPS_TYPE,groupDescStat.getGroupType() );
     }
 
-    @Test
-    public void getGroupActionsSupportBitmap() {
-        ActionType actionSupported = new ActionType(true,true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true);
-        final List<Long> groupActionsSupportBitmap = SinglePurposeMultipartReplyTranslator.getGroupActionsSupportBitmap(Lists.newArrayList(actionSupported));
-        assertEquals(1, groupActionsSupportBitmap.size());
-        final Long bitmap = groupActionsSupportBitmap.get(0);
-        assertEquals(GROUP_ACTION_BITMAP, bitmap);
-    }
-
     private MultipartReplyBody prepareMultipartReplyGroupDesc() {
         MultipartReplyGroupDescCaseBuilder multipartReplyGroupDescCaseBuilder = new MultipartReplyGroupDescCaseBuilder();
         MultipartReplyGroupDescBuilder multipartReplyGroupDescBuilder = new MultipartReplyGroupDescBuilder();
index 37500c4661c6b0846d8cac4be08deb9917b6677b..e433a499208c931d594b794c87eb538f1422e5a7 100644 (file)
@@ -8,6 +8,8 @@
 
 package org.opendaylight.openflowplugin.impl.util;
 
+import static org.junit.Assert.assertEquals;
+
 import com.google.common.base.Function;
 import com.google.common.collect.Lists;
 import java.util.Collections;
@@ -28,6 +30,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.ActionType;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.opendaylight.yangtools.yang.common.RpcError;
 import org.opendaylight.yangtools.yang.common.RpcResult;
@@ -41,6 +44,7 @@ public class GroupUtilTest {
     public static final NodeId DUMMY_NODE_ID = new NodeId("dummyNodeId");
     private static final GroupId DUMMY_GROUP_ID = new GroupId(42L);
     private static final GroupId DUMMY_GROUP_ID_2 = new GroupId(43L);
+    private static final Long GROUP_ACTION_BITMAP = 0b00000000000000000000000000000000000001111111111111001100000000001L;
 
     @Test
     public void testBuildGroupPath() throws Exception {
@@ -202,6 +206,15 @@ public class GroupUtilTest {
         Assert.assertEquals(1, composite.getResult().getBatchFailedGroupsOutput().size());
     }
 
+    @Test
+    public void testExtractGroupActionsSupportBitmap() {
+        ActionType actionSupported = new ActionType(true,true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true);
+        final List<Long> groupActionsSupportBitmap = GroupUtil.extractGroupActionsSupportBitmap(Lists.newArrayList(actionSupported));
+        assertEquals(1, groupActionsSupportBitmap.size());
+        final Long bitmap = groupActionsSupportBitmap.get(0);
+        assertEquals(GROUP_ACTION_BITMAP, bitmap);
+    }
+
     private RpcResult<Void> createBarrierFailureOutcome() {
         return RpcResultBuilder.<Void>failed()
                 .withError(RpcError.ErrorType.APPLICATION, "ut-barrier-error")
index a731bedb1686be91e6be3007b04b92894ecb9ff1..e35f22e0de9146ce973bca6600a9e54d03ca2f5b 100644 (file)
           <artifactId>org.eclipse.equinox.console</artifactId>
           <scope>test</scope>
         </dependency>
-        <dependency>
-          <groupId>equinoxSDK381</groupId>
-          <artifactId>org.apache.felix.gogo.command</artifactId>
-          <scope>test</scope>
-        </dependency>
-        <dependency>
-          <groupId>equinoxSDK381</groupId>
-          <artifactId>org.apache.felix.gogo.runtime</artifactId>
-          <scope>test</scope>
-        </dependency>
-        <dependency>
-          <groupId>equinoxSDK381</groupId>
-          <artifactId>org.apache.felix.gogo.shell</artifactId>
-          <scope>test</scope>
-        </dependency>
         <dependency>
           <groupId>org.opendaylight.controller</groupId>
           <artifactId>logback-config</artifactId>
index 8d3c01fb759c2561854ec1bcc1d866b455891b27..75c7f7ad8bd2521c62254ce562435de3249e7aa3 100644 (file)
@@ -54,10 +54,7 @@ public abstract class OFPaxOptionsAssistant {
         if (System.getProperty(INSPECT_OSGI) != null) {
             option
             .add(CoreOptions.vmOption("-Xrunjdwp:transport=dt_socket,server=y,suspend=n,address="+DEBUG_PORT))
-            .add(CoreOptions.mavenBundle("equinoxSDK381", "org.eclipse.equinox.console").versionAsInProject())
-            .add(CoreOptions.mavenBundle("equinoxSDK381", "org.apache.felix.gogo.shell").versionAsInProject())
-            .add(CoreOptions.mavenBundle("equinoxSDK381", "org.apache.felix.gogo.runtime").versionAsInProject())
-            .add(CoreOptions.mavenBundle("equinoxSDK381", "org.apache.felix.gogo.command").versionAsInProject());
+            .add(CoreOptions.mavenBundle("equinoxSDK381", "org.eclipse.equinox.console").versionAsInProject()));
         }
 
         return option;