package org.opendaylight.openflowplugin.applications.frsync;
import java.util.EventListener;
-
import org.opendaylight.controller.md.sal.binding.api.DataTreeChangeListener;
import org.opendaylight.yangtools.yang.binding.DataObject;
package org.opendaylight.openflowplugin.applications.frsync;
+import com.google.common.util.concurrent.ListenableFuture;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
-import com.google.common.util.concurrent.ListenableFuture;
-
/**
* Device synchronization API.
*/
\r
package org.opendaylight.openflowplugin.applications.frsync.dao;\r
\r
+import com.google.common.base.Optional;\r
import javax.annotation.Nonnull;\r
-\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;\r
\r
-import com.google.common.base.Optional;\r
-\r
/**\r
* Implementation of data access object for {@link FlowCapableNode}.\r
* Contains pair of snapshot and odl DAOs.\r
\r
package org.opendaylight.openflowplugin.applications.frsync.dao;\r
\r
+import com.google.common.base.Optional;\r
import javax.annotation.Nonnull;\r
-\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;\r
\r
-import com.google.common.base.Optional;\r
-\r
/**\r
* Data access object for {@link FlowCapableNode}.\r
*/\r
package org.opendaylight.openflowplugin.applications.frsync.dao;\r
\r
import com.google.common.base.Optional;\r
-\r
import java.util.concurrent.TimeUnit;\r
import java.util.concurrent.TimeoutException;\r
-\r
import javax.annotation.Nonnull;\r
import org.opendaylight.controller.md.sal.binding.api.DataBroker;\r
import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction;\r
\r
package org.opendaylight.openflowplugin.applications.frsync.dao;\r
\r
+import com.google.common.base.Optional;\r
import java.util.concurrent.ConcurrentHashMap;\r
-\r
import javax.annotation.Nonnull;\r
-\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;\r
\r
-import com.google.common.base.Optional;\r
-\r
/**\r
* Adding cache to data access object of {@link FlowCapableNode}.\r
*/\r
protected abstract Optional<ListenableFuture<Boolean>> processNodeModification(
DataTreeModification<T> modification) throws ReadFailedException, InterruptedException;
- public abstract LogicalDatastoreType dsType();
+ protected abstract LogicalDatastoreType dsType();
- static String threadName() {
+ private static String threadName() {
final Thread currentThread = Thread.currentThread();
return currentThread.getName();
}
package org.opendaylight.openflowplugin.applications.frsync.impl;
+import com.google.common.base.Preconditions;
import java.util.concurrent.Future;
-
import org.opendaylight.openflowplugin.applications.frsync.ForwardingRulesCommitter;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.Table;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.flow.update.OriginalFlowBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.flow.update.UpdatedFlowBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowRef;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.groups.Group;
import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRef;
import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import com.google.common.base.Preconditions;
-
/**
* Implements {@link ForwardingRulesCommitter} methods for processing add, update and remove of {@link Flow}.
*/
import org.opendaylight.openflowplugin.common.wait.SimpleTaskRetryLooper;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.SalFlatBatchService;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.SalFlowService;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.transaction.rev150304.FlowCapableTransactionService;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.SalGroupService;
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.meter.service.rev130918.SalMeterService;
import org.opendaylight.yang.gen.v1.urn.opendaylight.table.service.rev131026.SalTableService;
import org.opendaylight.yangtools.concepts.ListenerRegistration;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
public static final int STARTUP_LOOP_MAX_RETRIES = 8;
private final DataBroker dataService;
- private final SalFlowService salFlowService;
- private final SalGroupService salGroupService;
- private final SalMeterService salMeterService;
private final SalTableService salTableService;
- private final FlowCapableTransactionService transactionService;
private final SalFlatBatchService flatBatchService;
/** wildcard path to flow-capable-node augmentation of inventory node */
public ForwardingRulesSyncProvider(final BindingAwareBroker broker,
final DataBroker dataBroker,
final RpcConsumerRegistry rpcRegistry) {
- this.dataService = Preconditions.checkNotNull(dataBroker, "DataBroker can not be null!");
-
Preconditions.checkArgument(rpcRegistry != null, "RpcConsumerRegistry can not be null !");
-
- this.salFlowService = Preconditions.checkNotNull(rpcRegistry.getRpcService(SalFlowService.class),
- "RPC SalFlowService not found.");
- this.salGroupService = Preconditions.checkNotNull(rpcRegistry.getRpcService(SalGroupService.class),
- "RPC SalGroupService not found.");
- this.salMeterService = Preconditions.checkNotNull(rpcRegistry.getRpcService(SalMeterService.class),
- "RPC SalMeterService not found.");
+ this.dataService = Preconditions.checkNotNull(dataBroker, "DataBroker can not be null!");
this.salTableService = Preconditions.checkNotNull(rpcRegistry.getRpcService(SalTableService.class),
"RPC SalTableService not found.");
- this.transactionService =
- Preconditions.checkNotNull(rpcRegistry.getRpcService(FlowCapableTransactionService.class),
- "RPC SalTableService not found.");
- this.flatBatchService =
- Preconditions.checkNotNull(rpcRegistry.getRpcService(SalFlatBatchService.class),
- "RPC SalFlatBatchService not found.");
-
- nodeConfigDataTreePath =
- new DataTreeIdentifier<>(LogicalDatastoreType.CONFIGURATION, FLOW_CAPABLE_NODE_WC_PATH);
+ this.flatBatchService = Preconditions.checkNotNull(rpcRegistry.getRpcService(SalFlatBatchService.class),
+ "RPC SalFlatBatchService not found.");
+
+ nodeConfigDataTreePath = new DataTreeIdentifier<>(LogicalDatastoreType.CONFIGURATION, FLOW_CAPABLE_NODE_WC_PATH);
nodeOperationalDataTreePath = new DataTreeIdentifier<>(LogicalDatastoreType.OPERATIONAL, NODE_WC_PATH);
broker.registerProvider(this);
@Override
public void onSessionInitiated(final BindingAwareBroker.ProviderContext providerContext) {
- final FlowForwarder flowForwarder = new FlowForwarder(salFlowService);
- final GroupForwarder groupForwarder = new GroupForwarder(salGroupService);
- final MeterForwarder meterForwarder = new MeterForwarder(salMeterService);
final TableForwarder tableForwarder = new TableForwarder(salTableService);
- {
- //TODO: make is switchable
-// final SyncPlanPushStrategy syncPlanPushStrategy = new SyncPlanPushStrategyIncrementalImpl()
-// .setFlowForwarder(flowForwarder)
-// .setGroupForwarder(groupForwarder)
-// .setMeterForwarder(meterForwarder)
-// .setTableForwarder(tableForwarder)
-// .setTransactionService(transactionService);
-
- final SyncPlanPushStrategy syncPlanPushStrategy = new SyncPlanPushStrategyFlatBatchImpl()
- .setFlatBatchService(flatBatchService)
- .setTableForwarder(tableForwarder);
-
- final SyncReactorImpl syncReactorImpl = new SyncReactorImpl(syncPlanPushStrategy);
- final SyncReactor syncReactorGuard = new SyncReactorGuardDecorator(syncReactorImpl,
- new SemaphoreKeeperGuavaImpl<InstanceIdentifier<FlowCapableNode>>(1, true));
-
- final SyncReactor cfgReactor = new SyncReactorFutureWithCompressionDecorator(syncReactorGuard, syncThreadPool);
- final SyncReactor operReactor = new SyncReactorFutureWithCompressionDecorator(syncReactorGuard, syncThreadPool);
-
- final FlowCapableNodeSnapshotDao configSnapshot = new FlowCapableNodeSnapshotDao();
- final FlowCapableNodeSnapshotDao operationalSnapshot = new FlowCapableNodeSnapshotDao();
- final FlowCapableNodeDao configDao = new FlowCapableNodeCachedDao(configSnapshot,
- new FlowCapableNodeOdlDao(dataService, LogicalDatastoreType.CONFIGURATION));
- final FlowCapableNodeDao operationalDao = new FlowCapableNodeCachedDao(operationalSnapshot,
- new FlowCapableNodeOdlDao(dataService, LogicalDatastoreType.OPERATIONAL));
-
- final NodeListener<FlowCapableNode> nodeListenerConfig =
- new SimplifiedConfigListener(
- cfgReactor,
- configSnapshot, operationalDao);
- final NodeListener<Node> nodeListenerOperational =
- new SimplifiedOperationalListener(operReactor, operationalSnapshot, configDao);
-
- try {
- SimpleTaskRetryLooper looper1 = new SimpleTaskRetryLooper(STARTUP_LOOP_TICK, STARTUP_LOOP_MAX_RETRIES);
- dataTreeConfigChangeListener = looper1.loopUntilNoException(
- new Callable<ListenerRegistration<NodeListener>>() {
- @Override
- public ListenerRegistration<NodeListener> call() throws Exception {
- return dataService.registerDataTreeChangeListener(
- nodeConfigDataTreePath, nodeListenerConfig);
- }
- });
-
- SimpleTaskRetryLooper looper2 = new SimpleTaskRetryLooper(STARTUP_LOOP_TICK, STARTUP_LOOP_MAX_RETRIES);
- dataTreeOperationalChangeListener = looper2.loopUntilNoException(
- new Callable<ListenerRegistration<NodeListener>>() {
- @Override
- public ListenerRegistration<NodeListener> call() throws Exception {
- return dataService.registerDataTreeChangeListener(
- nodeOperationalDataTreePath, nodeListenerOperational);
- }
- });
- } catch (final Exception e) {
- LOG.warn("FR-Sync node DataChange listener registration fail!", e);
- throw new IllegalStateException("FR-Sync startup fail!", e);
- }
+ final SyncPlanPushStrategy syncPlanPushStrategy = new SyncPlanPushStrategyFlatBatchImpl()
+ .setFlatBatchService(flatBatchService)
+ .setTableForwarder(tableForwarder);
+
+ final SyncReactorImpl syncReactorImpl = new SyncReactorImpl(syncPlanPushStrategy);
+ final SyncReactor syncReactorGuard = new SyncReactorGuardDecorator(syncReactorImpl,
+ new SemaphoreKeeperGuavaImpl<InstanceIdentifier<FlowCapableNode>>(1, true));
+
+ final SyncReactor cfgReactor = new SyncReactorFutureWithCompressionDecorator(syncReactorGuard, syncThreadPool);
+ final SyncReactor operReactor = new SyncReactorFutureWithCompressionDecorator(syncReactorGuard, syncThreadPool);
+
+ final FlowCapableNodeSnapshotDao configSnapshot = new FlowCapableNodeSnapshotDao();
+ final FlowCapableNodeSnapshotDao operationalSnapshot = new FlowCapableNodeSnapshotDao();
+ final FlowCapableNodeDao configDao = new FlowCapableNodeCachedDao(configSnapshot,
+ new FlowCapableNodeOdlDao(dataService, LogicalDatastoreType.CONFIGURATION));
+ final FlowCapableNodeDao operationalDao = new FlowCapableNodeCachedDao(operationalSnapshot,
+ new FlowCapableNodeOdlDao(dataService, LogicalDatastoreType.OPERATIONAL));
+
+ final NodeListener<FlowCapableNode> nodeListenerConfig = new SimplifiedConfigListener(cfgReactor, configSnapshot, operationalDao);
+ final NodeListener<Node> nodeListenerOperational = new SimplifiedOperationalListener(operReactor, operationalSnapshot, configDao);
+
+ try {
+ SimpleTaskRetryLooper looper1 = new SimpleTaskRetryLooper(STARTUP_LOOP_TICK, STARTUP_LOOP_MAX_RETRIES);
+ dataTreeConfigChangeListener = looper1.loopUntilNoException(
+ new Callable<ListenerRegistration<NodeListener>>() {
+ @Override
+ public ListenerRegistration<NodeListener> call() throws Exception {
+ return dataService.registerDataTreeChangeListener(
+ nodeConfigDataTreePath, nodeListenerConfig);
+ }
+ });
+
+ SimpleTaskRetryLooper looper2 = new SimpleTaskRetryLooper(STARTUP_LOOP_TICK, STARTUP_LOOP_MAX_RETRIES);
+ dataTreeOperationalChangeListener = looper2.loopUntilNoException(
+ new Callable<ListenerRegistration<NodeListener>>() {
+ @Override
+ public ListenerRegistration<NodeListener> call() throws Exception {
+ return dataService.registerDataTreeChangeListener(
+ nodeOperationalDataTreePath, nodeListenerOperational);
+ }
+ });
+ } catch (final Exception e) {
+ LOG.warn("FR-Sync node DataChange listener registration fail!", e);
+ throw new IllegalStateException("FR-Sync startup fail!", e);
}
LOG.info("ForwardingRulesSync has started.");
}
\r
package org.opendaylight.openflowplugin.applications.frsync.impl;\r
\r
-import java.util.concurrent.ExecutorService;\r
-import java.util.concurrent.Executors;\r
-import java.util.concurrent.ThreadFactory;\r
-\r
import com.google.common.annotations.VisibleForTesting;\r
import com.google.common.util.concurrent.ListeningExecutorService;\r
import com.google.common.util.concurrent.MoreExecutors;\r
+import java.util.concurrent.ExecutorService;\r
+import java.util.concurrent.Executors;\r
+import java.util.concurrent.ThreadFactory;\r
\r
/**\r
- * Static Factory for creating ExecutorServicess (because there is no dependency injection but\r
+ * Static Factory for creating ExecutorServices (because there is no dependency injection but\r
* static getInstance).\r
*/\r
public final class FrmExecutors {\r
- public static PceExecursFactory instance() {\r
+ public static PceExecutorsFactory instance() {\r
return DEFAULT_EXECUTORS;\r
}\r
\r
- public interface PceExecursFactory {\r
+ public interface PceExecutorsFactory {\r
\r
- public ListeningExecutorService newFixedThreadPool(int nThreads, ThreadFactory factory);\r
+ ListeningExecutorService newFixedThreadPool(int nThreads, ThreadFactory factory);\r
}\r
\r
/**\r
* This will be rewritten in JUnits using SynchronousExecutorService\r
*/\r
@VisibleForTesting // should not be private and final\r
- static PceExecursFactory DEFAULT_EXECUTORS = new PceExecursFactory() {\r
+ static PceExecutorsFactory DEFAULT_EXECUTORS = new PceExecutorsFactory() {\r
\r
public ListeningExecutorService newFixedThreadPool(int nThreads, ThreadFactory factory) {\r
final ExecutorService executorService = Executors.newFixedThreadPool(nThreads, factory);\r
package org.opendaylight.openflowplugin.applications.frsync.impl;
import java.util.concurrent.Future;
-
import org.opendaylight.openflowplugin.applications.frsync.ForwardingRulesCommitter;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.meters.Meter;
package org.opendaylight.openflowplugin.applications.frsync.impl;
+import com.google.common.base.Optional;
+import com.google.common.util.concurrent.ListenableFuture;
import java.util.Collection;
-
import org.opendaylight.controller.md.sal.binding.api.DataObjectModification;
import org.opendaylight.controller.md.sal.binding.api.DataTreeModification;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import com.google.common.base.Optional;
-import com.google.common.util.concurrent.ListenableFuture;
-
/**
* Listens to config changes and delegates add/remove/update/barrier to {@link SyncReactor}.
*/
public class SimplifiedConfigListener extends AbstractFrmSyncListener<FlowCapableNode> {
private static final Logger LOG = LoggerFactory.getLogger(SimplifiedConfigListener.class);
- protected final SyncReactor reactor;
+ private final SyncReactor reactor;
private final FlowCapableNodeSnapshotDao configSnaphot;
private final FlowCapableNodeDao operationalDao;
package org.opendaylight.openflowplugin.applications.frsync.impl;
+import com.google.common.base.Optional;
+import com.google.common.util.concurrent.ListenableFuture;
import java.util.Collection;
import java.util.List;
-
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.DataTreeModification;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import com.google.common.base.Optional;
-import com.google.common.util.concurrent.ListenableFuture;
-
/**
* Listens to operational new nodes and delegates add/remove/update/barrier to {@link SyncReactor}.
*/
public class SimplifiedOperationalListener extends AbstractFrmSyncListener<Node> {
private static final Logger LOG = LoggerFactory.getLogger(SimplifiedOperationalListener.class);
- protected final SyncReactor reactor;
-
- private FlowCapableNodeSnapshotDao operationalSnaphot;
-
+ private final SyncReactor reactor;
+ private FlowCapableNodeSnapshotDao operationalSnapshot;
private FlowCapableNodeDao configDao;
public SimplifiedOperationalListener(SyncReactor reactor,
- FlowCapableNodeSnapshotDao operationalSnaphot, FlowCapableNodeDao configDao) {
+ FlowCapableNodeSnapshotDao operationalSnapshot, FlowCapableNodeDao configDao) {
this.reactor = reactor;
- this.operationalSnaphot = operationalSnaphot;
+ this.operationalSnapshot = operationalSnapshot;
this.configDao = configDao;
}
/**
* Remove if delete. Update only if FlowCapableNode Augmentation modified.
*
- * @param modification
+ * @param modification Datastore modification
*/
protected void updateCache(DataTreeModification<Node> modification) {
try {
boolean isDelete = isDelete(modification) || isDeleteLogical(modification);
if (isDelete) {
- operationalSnaphot.updateCache(nodeId(modification), Optional.<FlowCapableNode>absent());
+ operationalSnapshot.updateCache(nodeId(modification), Optional.<FlowCapableNode>absent());
return;
}
- operationalSnaphot.updateCache(nodeId(modification), Optional.fromNullable(flowCapableNodeAfter(modification)));
+ operationalSnapshot.updateCache(nodeId(modification), Optional.fromNullable(flowCapableNodeAfter(modification)));
} catch(Exception e) {
LOG.error("update cache failed {}", nodeId(modification), e);
}
}
final List<NodeConnector> nodeConnectors = node.getNodeConnector();
- if (nodeConnectors == null || nodeConnectors.isEmpty()) {
- return true;
- }
- return false;
+ return nodeConnectors == null || nodeConnectors.isEmpty();
}
static String nodeIdValue(DataTreeModification<Node> modification) {
\r
package org.opendaylight.openflowplugin.applications.frsync.impl;\r
\r
+import com.google.common.util.concurrent.ListenableFuture;\r
+import com.google.common.util.concurrent.ListeningExecutorService;\r
import java.util.concurrent.Callable;\r
import java.util.concurrent.TimeUnit;\r
import java.util.concurrent.TimeoutException;\r
-\r
import org.opendaylight.openflowplugin.applications.frsync.SyncReactor;\r
import org.opendaylight.openflowplugin.applications.frsync.util.PathUtil;\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;\r
import org.slf4j.Logger;\r
import org.slf4j.LoggerFactory;\r
\r
-import com.google.common.util.concurrent.ListenableFuture;\r
-import com.google.common.util.concurrent.ListeningExecutorService;\r
-\r
/**\r
* Decorator for running delegate syncup in Future.\r
*/\r
\r
package org.opendaylight.openflowplugin.applications.frsync.impl;\r
\r
+import com.google.common.util.concurrent.Futures;\r
+import com.google.common.util.concurrent.ListenableFuture;\r
+import com.google.common.util.concurrent.ListeningExecutorService;\r
import java.util.HashMap;\r
import java.util.Map;\r
import java.util.concurrent.Semaphore;\r
-\r
import javax.annotation.concurrent.GuardedBy;\r
-\r
import org.apache.commons.lang3.tuple.Pair;\r
import org.opendaylight.openflowplugin.applications.frsync.SyncReactor;\r
import org.opendaylight.openflowplugin.applications.frsync.util.PathUtil;\r
import org.slf4j.Logger;\r
import org.slf4j.LoggerFactory;\r
\r
-import com.google.common.util.concurrent.Futures;\r
-import com.google.common.util.concurrent.ListenableFuture;\r
-import com.google.common.util.concurrent.ListeningExecutorService;\r
-\r
/**\r
* Enriches {@link SyncReactorFutureDecorator} with state compression.\r
*/\r
\r
private static final Logger LOG = LoggerFactory.getLogger(SyncReactorFutureWithCompressionDecorator.class);\r
\r
- @GuardedBy("beforeCompressionGuard")\r
- final Map<InstanceIdentifier<FlowCapableNode>, Pair<FlowCapableNode, FlowCapableNode>> beforeCompression =\r
+ @GuardedBy("compressionGuard")\r
+ final Map<InstanceIdentifier<FlowCapableNode>, Pair<FlowCapableNode, FlowCapableNode>> compressionQueue =\r
new HashMap<>();\r
- final Semaphore beforeCompressionGuard = new Semaphore(1, false);\r
+ final Semaphore compressionGuard = new Semaphore(1, false);\r
\r
public SyncReactorFutureWithCompressionDecorator(SyncReactor delegate, ListeningExecutorService executorService) {\r
super(delegate, executorService);\r
LOG.trace("syncup {}", nodeId.getValue());\r
\r
try {\r
- beforeCompressionGuard.acquire();\r
+ compressionGuard.acquire();\r
\r
final boolean newFutureNecessary = updateCompressionState(flowcapableNodePath, configTree, operationalTree);\r
if (newFutureNecessary) {\r
}\r
return Futures.immediateFuture(true);\r
} finally {\r
- beforeCompressionGuard.release();\r
+ compressionGuard.release();\r
}\r
}\r
\r
\r
protected boolean updateCompressionState(final InstanceIdentifier<FlowCapableNode> flowcapableNodePath,\r
final FlowCapableNode configTree, final FlowCapableNode operationalTree) {\r
- final Pair<FlowCapableNode, FlowCapableNode> previous = beforeCompression.get(flowcapableNodePath);\r
+ final Pair<FlowCapableNode, FlowCapableNode> previous = compressionQueue.get(flowcapableNodePath);\r
if (previous != null) {\r
final FlowCapableNode previousOperational = previous.getRight();\r
- beforeCompression.put(flowcapableNodePath, Pair.of(configTree, previousOperational));\r
+ compressionQueue.put(flowcapableNodePath, Pair.of(configTree, previousOperational));\r
return false;\r
} else {\r
- beforeCompression.put(flowcapableNodePath, Pair.of(configTree, operationalTree));\r
+ compressionQueue.put(flowcapableNodePath, Pair.of(configTree, operationalTree));\r
return true;\r
}\r
}\r
final InstanceIdentifier<FlowCapableNode> flowcapableNodePath) {\r
try {\r
try {\r
- beforeCompressionGuard.acquire();\r
+ compressionGuard.acquire();\r
} catch (InterruptedException e) {\r
return null;\r
}\r
\r
- return beforeCompression.remove(flowcapableNodePath);\r
+ return compressionQueue.remove(flowcapableNodePath);\r
} finally {\r
- beforeCompressionGuard.release();\r
+ compressionGuard.release();\r
}\r
}\r
}\r
\r
package org.opendaylight.openflowplugin.applications.frsync.impl;\r
\r
+import com.google.common.base.Preconditions;\r
+import com.google.common.util.concurrent.FutureCallback;\r
+import com.google.common.util.concurrent.Futures;\r
+import com.google.common.util.concurrent.ListenableFuture;\r
import java.util.concurrent.Semaphore;\r
import java.util.concurrent.TimeUnit;\r
-\r
import javax.annotation.Nullable;\r
-\r
import org.opendaylight.openflowplugin.applications.frsync.SemaphoreKeeper;\r
import org.opendaylight.openflowplugin.applications.frsync.SyncReactor;\r
import org.opendaylight.openflowplugin.applications.frsync.util.PathUtil;\r
import org.slf4j.Logger;\r
import org.slf4j.LoggerFactory;\r
\r
-import com.google.common.base.Preconditions;\r
-import com.google.common.util.concurrent.FutureCallback;\r
-import com.google.common.util.concurrent.Futures;\r
-import com.google.common.util.concurrent.ListenableFuture;\r
-\r
/**\r
* Decorator for NodeId level syncup locking.\r
*/\r
formatNanos(stampAfterGuard - stampBeforeGuard),\r
guard, threadName());\r
}\r
- \r
- lockReleaseForNodeId(nodeId, guard);\r
+\r
+ releaseGuardForNodeId(nodeId, guard);\r
}\r
- \r
+\r
@Override\r
public void onFailure(final Throwable t) {\r
if (LOG.isDebugEnabled()) {\r
formatNanos(stampAfterGuard - stampBeforeGuard),\r
guard, threadName());\r
}\r
- \r
- lockReleaseForNodeId(nodeId, guard);\r
+\r
+ releaseGuardForNodeId(nodeId, guard);\r
}\r
});\r
return endResult;\r
} catch(InterruptedException e) {\r
- lockReleaseForNodeId(nodeId, guard);\r
+ releaseGuardForNodeId(nodeId, guard);\r
throw e;\r
}\r
}\r
/**\r
* get guard\r
*\r
- * @param flowcapableNodePath\r
- * @return\r
+ * @param flowcapableNodePath II of node for which guard should be acquired\r
+ * @return semaphore guard\r
*/\r
protected Semaphore summonGuardAndAcquire(final InstanceIdentifier<FlowCapableNode> flowcapableNodePath)\r
throws InterruptedException {\r
/**\r
* unlock per node\r
*\r
- * @param nodeId\r
- * @param guard\r
+ * @param nodeId NodeId of node which should be unlocked\r
+ * @param guard semaphore guard\r
*/\r
- protected void lockReleaseForNodeId(final NodeId nodeId,\r
- final Semaphore guard) {\r
+ protected void releaseGuardForNodeId(final NodeId nodeId, final Semaphore guard) {\r
if (guard == null) {\r
return;\r
}\r
import java.util.Collections;
import java.util.concurrent.Future;
-
import org.opendaylight.openflowplugin.applications.frsync.ForwardingRulesUpdateCommitter;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.Table;
@Override
public void onSuccess(@Nullable final RpcResult<ProcessFlatBatchOutput> result) {
if (!result.isSuccessful() && result.getResult() != null && !result.getResult().getBatchFailure().isEmpty()) {
- Map<Range<Integer>, Batch> batchMap = mapBachesToRanges(inputBatchBag, failureIndexLimit);
+ Map<Range<Integer>, Batch> batchMap = mapBatchesToRanges(inputBatchBag, failureIndexLimit);
for (BatchFailure batchFailure : result.getResult().getBatchFailure()) {
for (Map.Entry<Range<Integer>, Batch> rangeBatchEntry : batchMap.entrySet()) {
}
}
- static Map<Range<Integer>, Batch> mapBachesToRanges(final List<Batch> inputBatchBag, final int failureIndexLimit) {
+ static Map<Range<Integer>, Batch> mapBatchesToRanges(final List<Batch> inputBatchBag, final int failureIndexLimit) {
final Map<Range<Integer>, Batch> batchMap = new LinkedHashMap<>();
final PeekingIterator<Batch> batchPeekingIterator = Iterators.peekingIterator(inputBatchBag.iterator());
while (batchPeekingIterator.hasNext()) {
// process flow remove
if (flowItemSyncTableMap != null) {
for (Map.Entry<TableKey, ItemSyncBox<Flow>> syncBoxEntry : flowItemSyncTableMap.entrySet()) {
- final TableKey tableKey = syncBoxEntry.getKey();
final ItemSyncBox<Flow> flowItemSyncBox = syncBoxEntry.getValue();
if (!flowItemSyncBox.getItemsToPush().isEmpty()) {
// process flow add+update
if (flowItemSyncTableMap != null) {
for (Map.Entry<TableKey, ItemSyncBox<Flow>> syncBoxEntry : flowItemSyncTableMap.entrySet()) {
- final TableKey tableKey = syncBoxEntry.getKey();
final ItemSyncBox<Flow> flowItemSyncBox = syncBoxEntry.getValue();
if (!flowItemSyncBox.getItemsToPush().isEmpty()) {
import java.util.Map;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
-
import org.opendaylight.openflowplugin.applications.frsync.markandsweep.SwitchFlowId;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowId;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.meters.Meter;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.Table;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow;
package org.opendaylight.openflowplugin.applications.frsync.util;
-import java.util.concurrent.Semaphore;
-
-import javax.annotation.Nonnull;
-
-import org.opendaylight.openflowplugin.applications.frsync.SemaphoreKeeper;
-
import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
+import java.util.concurrent.Semaphore;
+import javax.annotation.Nonnull;
+import org.opendaylight.openflowplugin.applications.frsync.SemaphoreKeeper;
/**
* Key-based semaphore provider.
import java.util.Collections;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
-
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.opendaylight.controller.md.sal.binding.api.DataTreeIdentifier;
import org.opendaylight.controller.sal.binding.api.BindingAwareBroker;
import org.opendaylight.controller.sal.binding.api.RpcConsumerRegistry;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.SalFlatBatchService;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.SalFlowService;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.transaction.rev150304.FlowCapableTransactionService;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.SalGroupService;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.SalMeterService;
import org.opendaylight.yang.gen.v1.urn.opendaylight.table.service.rev131026.SalTableService;
import org.opendaylight.yangtools.yang.binding.RpcService;
});
provider = new ForwardingRulesSyncProvider(broker, dataBroker, rpcRegistry);
-
- Mockito.verify(rpcRegistry).getRpcService(SalFlowService.class);
- Mockito.verify(rpcRegistry).getRpcService(SalGroupService.class);
- Mockito.verify(rpcRegistry).getRpcService(SalMeterService.class);
Mockito.verify(rpcRegistry).getRpcService(SalTableService.class);
- Mockito.verify(rpcRegistry).getRpcService(FlowCapableTransactionService.class);
-
+ Mockito.verify(rpcRegistry).getRpcService(SalFlatBatchService.class);
Mockito.verify(broker).registerProvider(provider);
}
import java.math.BigInteger;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
-
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import java.math.BigInteger;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
-
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
package org.opendaylight.openflowplugin.applications.frsync.impl;
+import com.google.common.base.Optional;
+import com.google.common.util.concurrent.Futures;
import java.util.Collections;
-
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
-import com.google.common.base.Optional;
-import com.google.common.util.concurrent.Futures;
-
/**
* Test for {@link SimplifiedConfigListener}.
*/
-@SuppressWarnings("deprecation")
@RunWith(MockitoJUnitRunner.class)
public class SimplifiedConfigListenerTest {
package org.opendaylight.openflowplugin.applications.frsync.impl;
+import com.google.common.base.Optional;
+import com.google.common.util.concurrent.Futures;
import java.util.Collections;
-
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
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.yangtools.yang.binding.InstanceIdentifier;
-import org.opendaylight.yangtools.yang.common.RpcResult;
-
-import com.google.common.base.Optional;
-import com.google.common.util.concurrent.AsyncFunction;
-import com.google.common.util.concurrent.Futures;
/**
* Test for {@link SimplifiedOperationalListener}.
*/
-@SuppressWarnings("deprecation")
@RunWith(MockitoJUnitRunner.class)
public class SimplifiedOperationalListenerTest {
private InstanceIdentifier<FlowCapableNode> fcNodePath;
private SimplifiedOperationalListener nodeListenerOperational;
- @SuppressWarnings("deprecation")
@Before
public void setUp() throws Exception {
final FlowCapableNodeSnapshotDao configSnaphot = new FlowCapableNodeSnapshotDao();
--- /dev/null
+/**
+ * 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.applications.frsync.impl;
+
+import com.google.common.util.concurrent.Futures;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Matchers;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.runners.MockitoJUnitRunner;
+import org.opendaylight.openflowplugin.applications.frsync.util.SemaphoreKeeperGuavaImpl;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
+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.yangtools.yang.binding.InstanceIdentifier;
+
+/**
+ * Test for {@link SyncReactorGuardDecorator}.
+ */
+@RunWith(MockitoJUnitRunner.class)
+public class SyncReactorGuardDecoratorTest {
+
+ private static final NodeId NODE_ID = new NodeId("test-node");
+ private SyncReactorGuardDecorator reactor;
+ private InstanceIdentifier<FlowCapableNode> fcNodePath;
+
+ @Mock
+ private SyncReactorImpl delegate;
+ @Mock
+ private FlowCapableNode fcConfigNode;
+ @Mock
+ private FlowCapableNode fcOperationalNode;
+
+ @Before
+ public void setUp() throws Exception {
+ reactor = new SyncReactorGuardDecorator(delegate, new SemaphoreKeeperGuavaImpl<InstanceIdentifier<FlowCapableNode>>(1, true));
+ InstanceIdentifier<Node> nodePath = InstanceIdentifier.create(Nodes.class).child(Node.class, new NodeKey(NODE_ID));
+ fcNodePath = nodePath.augmentation(FlowCapableNode.class);
+
+ final Node operationalNode = Mockito.mock(Node.class);
+ Mockito.when(operationalNode.getId()).thenReturn(NODE_ID);
+ Mockito.when(operationalNode.getAugmentation(FlowCapableNode.class)).thenReturn(fcOperationalNode);
+ }
+
+ @Test
+ public void testSyncupSuccess() throws Exception {
+ Mockito.when(delegate.syncup(Matchers.<InstanceIdentifier<FlowCapableNode>>any(),Matchers.<FlowCapableNode>any(),
+ Matchers.<FlowCapableNode>any())).thenReturn(Futures.immediateFuture(Boolean.TRUE));
+ reactor.syncup(fcNodePath, fcConfigNode, fcOperationalNode);
+ Mockito.verify(delegate).syncup(fcNodePath, fcConfigNode, fcOperationalNode);
+
+ }
+
+ @Test
+ public void testSyncupFail() throws Exception {
+ Mockito.when(delegate.syncup(Matchers.<InstanceIdentifier<FlowCapableNode>>any(),Matchers.<FlowCapableNode>any(),
+ Matchers.<FlowCapableNode>any())).thenReturn(Futures.immediateFailedFuture(new Exception()));
+ reactor.syncup(fcNodePath, fcConfigNode, fcOperationalNode);
+ Mockito.verify(delegate).syncup(fcNodePath, fcConfigNode, fcOperationalNode);
+
+ }
+
+}
\ No newline at end of file
import java.math.BigInteger;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
-
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
return groupBox;
}
- static Group createPlainGroup(final long gid) {
+ private static Group createPlainGroup(final long gid) {
return new GroupBuilder().setGroupId(new GroupId(gid)).build();
}
return groupBox;
}
- static Meter createPlainMeter(final long mid) {
+ private static Meter createPlainMeter(final long mid) {
return new MeterBuilder().setMeterId(new MeterId(mid)).build();
}
return groupBox;
}
- static Flow createPlainFlow(final String fid) {
+ private static Flow createPlainFlow(final String fid) {
return new FlowBuilder().setId(new FlowId(fid)).build();
}
}
new BatchBuilder().setBatchOrder(9).build(),
new BatchBuilder().setBatchOrder(15).build()
);
- final Map<Range<Integer>, Batch> rangeBatchMap = SyncPlanPushStrategyFlatBatchImpl.mapBachesToRanges(inputBatchBag, 42);
+ final Map<Range<Integer>, Batch> rangeBatchMap = SyncPlanPushStrategyFlatBatchImpl.mapBatchesToRanges(inputBatchBag, 42);
Assert.assertEquals(4, rangeBatchMap.size());
int idx = 0;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.SettableFuture;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
import org.junit.Assert;
import org.junit.Rule;
import org.junit.Test;
import org.opendaylight.yangtools.yang.common.RpcResult;
import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
/**
* Test for {@link ReconcileUtil}.
*/
import java.util.concurrent.Semaphore;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
-
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
public class SemaphoreKeeperTest {
private static final Logger LOG = LoggerFactory.getLogger(SemaphoreKeeperTest.class);
private SemaphoreKeeperGuavaImpl<String> semaphoreKeeper;
- final String key = "11";
+ private final String key = "11";
@Before
public void setUp() throws Exception {