import com.google.common.base.Preconditions;
import com.google.common.util.concurrent.ListeningExecutorService;
+import com.google.common.util.concurrent.MoreExecutors;
import com.google.common.util.concurrent.ThreadFactoryBuilder;
-import java.lang.Thread.UncaughtExceptionHandler;
-import java.util.concurrent.Callable;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.TimeUnit;
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
import org.opendaylight.controller.md.sal.binding.api.DataTreeIdentifier;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
import org.opendaylight.openflowplugin.applications.frsync.impl.strategy.SyncPlanPushStrategyFlatBatchImpl;
import org.opendaylight.openflowplugin.applications.frsync.util.RetryRegistry;
import org.opendaylight.openflowplugin.applications.frsync.util.SemaphoreKeeperGuavaImpl;
-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.inventory.rev130819.Nodes;
public class ForwardingRulesSyncProvider implements AutoCloseable, BindingAwareProvider {
private static final Logger LOG = LoggerFactory.getLogger(ForwardingRulesSyncProvider.class);
- private static final int STARTUP_LOOP_TICK = 500;
- private static final int STARTUP_LOOP_MAX_RETRIES = 8;
private final DataBroker dataService;
private final SalTableService salTableService;
private static final InstanceIdentifier<Node> NODE_WC_PATH =
InstanceIdentifier.create(Nodes.class).child(Node.class);
-
private final DataTreeIdentifier<FlowCapableNode> nodeConfigDataTreePath;
private final DataTreeIdentifier<Node> nodeOperationalDataTreePath;
private ListenerRegistration<NodeListener> dataTreeConfigChangeListener;
private ListenerRegistration<NodeListener> dataTreeOperationalChangeListener;
+ private final ListeningExecutorService syncThreadPool;
+
public ForwardingRulesSyncProvider(final BindingAwareBroker broker,
final DataBroker dataBroker,
final RpcConsumerRegistry rpcRegistry) {
nodeConfigDataTreePath = new DataTreeIdentifier<>(LogicalDatastoreType.CONFIGURATION, FLOW_CAPABLE_NODE_WC_PATH);
nodeOperationalDataTreePath = new DataTreeIdentifier<>(LogicalDatastoreType.OPERATIONAL, NODE_WC_PATH);
+ final ExecutorService executorService= Executors.newCachedThreadPool(new ThreadFactoryBuilder()
+ .setNameFormat(SyncReactorFutureDecorator.FRM_RPC_CLIENT_PREFIX + "%d")
+ .setDaemon(false)
+ .setUncaughtExceptionHandler((thread, e) -> LOG.error("Uncaught exception {}", thread, e))
+ .build());
+ syncThreadPool = MoreExecutors.listeningDecorator(executorService);
+
broker.registerProvider(this);
}
- private final ListeningExecutorService syncThreadPool = FrmExecutors.instance()
- // TODO improve log in ThreadPoolExecutor.afterExecute
- // TODO max bloking queue size
- // TODO core/min pool size
- .newFixedThreadPool(6, new ThreadFactoryBuilder()
- .setNameFormat(SyncReactorFutureDecorator.FRM_RPC_CLIENT_PREFIX + "%d")
- .setDaemon(false)
- .setUncaughtExceptionHandler(new UncaughtExceptionHandler() {
- @Override
- public void uncaughtException(Thread thread, Throwable e) {
- LOG.error("uncaught exception {}", thread, e);
- }
- })
- .build());
-
@Override
public void onSessionInitiated(final BindingAwareBroker.ProviderContext providerContext) {
final TableForwarder tableForwarder = new TableForwarder(salTableService);
final NodeListener<Node> nodeListenerOperational =
new SimplifiedOperationalRetryListener(reactor, operationalSnapshot, configDao, retryRegistry);
- 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);
- }
+ dataTreeConfigChangeListener =
+ dataService.registerDataTreeChangeListener(nodeConfigDataTreePath, nodeListenerConfig);
+ dataTreeOperationalChangeListener =
+ dataService.registerDataTreeChangeListener(nodeOperationalDataTreePath, nodeListenerOperational);
+
LOG.info("ForwardingRulesSync has started.");
}
- public void close() throws Exception {
+ public void close() throws InterruptedException {
if (dataTreeConfigChangeListener != null) {
dataTreeConfigChangeListener.close();
dataTreeConfigChangeListener = null;
}
+
if (dataTreeOperationalChangeListener != null) {
dataTreeOperationalChangeListener.close();
dataTreeOperationalChangeListener = null;
+++ /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.annotations.VisibleForTesting;
-import com.google.common.util.concurrent.ListeningExecutorService;
-import com.google.common.util.concurrent.MoreExecutors;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-import java.util.concurrent.ThreadFactory;
-
-/**
- * Static Factory for creating ExecutorServices (because there is no dependency injection but
- * static getInstance).
- */
-public final class FrmExecutors {
- public static PceExecutorsFactory instance() {
- return DEFAULT_EXECUTORS;
- }
-
- public interface PceExecutorsFactory {
-
- ListeningExecutorService newFixedThreadPool(int nThreads, ThreadFactory factory);
- }
-
- /**
- * This will be rewritten in JUnits using SynchronousExecutorService.
- */
- @VisibleForTesting // should not be private and final
- static PceExecutorsFactory DEFAULT_EXECUTORS = new PceExecutorsFactory() {
-
- public ListeningExecutorService newFixedThreadPool(int nThreads, ThreadFactory factory) {
- final ExecutorService executorService = Executors.newFixedThreadPool(nThreads, factory);
- return MoreExecutors.listeningDecorator(executorService);
- }
- };
-}
LOG.trace("syncup guard {}", nodeId.getValue());
final long stampBeforeGuard = System.nanoTime();
- final Semaphore guard = summonGuardAndAcquire(flowcapableNodePath);//TODO handle InteruptedException
+ final Semaphore guard = summonGuardAndAcquire(flowcapableNodePath);
+ if (guard == null) {
+ return Futures.immediateFuture(false);
+ }
+ final long stampAfterGuard = System.nanoTime();
try {
- final long stampAfterGuard = System.nanoTime();
if (LOG.isDebugEnabled()) {
LOG.debug("syncup start {} waiting:{} guard:{} thread:{}", nodeId.getValue(),
formatNanos(stampAfterGuard - stampBeforeGuard),
}
final ListenableFuture<Boolean> endResult =
- delegate.syncup(flowcapableNodePath, configTree, operationalTree, dsType);//TODO handle InteruptedException
+ delegate.syncup(flowcapableNodePath, configTree, operationalTree, dsType);
Futures.addCallback(endResult, new FutureCallback<Boolean>() {
@Override
}
});
return endResult;
- } catch(InterruptedException e) {
+ } catch (InterruptedException e) {
releaseGuardForNodeId(guard);
throw e;
}
* @param flowcapableNodePath II of node for which guard should be acquired
* @return semaphore guard
*/
- private Semaphore summonGuardAndAcquire(final InstanceIdentifier<FlowCapableNode> flowcapableNodePath)
- throws InterruptedException {
+ private Semaphore summonGuardAndAcquire(final InstanceIdentifier<FlowCapableNode> flowcapableNodePath) {
+ final NodeId nodeId = PathUtil.digNodeId(flowcapableNodePath);
final Semaphore guard = Preconditions.checkNotNull(semaphoreKeeper.summonGuard(flowcapableNodePath),
- "no guard for " + flowcapableNodePath);
-
- if (LOG.isDebugEnabled()) {
- final NodeId nodeId = PathUtil.digNodeId(flowcapableNodePath);
- try {
- LOG.debug("syncup summon {} guard:{} thread:{}", nodeId.getValue(), guard, threadName());
- } catch (Exception e) {
- LOG.error("error logging guard after summon before aquiring {}", nodeId);
- }
+ "no guard for " + nodeId.getValue());
+ try {
+ guard.acquire();
+ } catch (InterruptedException e) {
+ LOG.error("syncup summon {} failed {}", nodeId.getValue(), e);
+ return null;
}
-
- guard.acquire();
+ LOG.trace("syncup summon {} guard:{} thread:{}", nodeId.getValue(), guard, threadName());
return guard;
}
* @param guard semaphore guard which should be unlocked
*/
private void releaseGuardForNodeId(final Semaphore guard) {
- if (guard == null) {
- return;
+ if (guard != null) {
+ guard.release();
+ LOG.trace("syncup release guard:{} thread:{}", guard, threadName());
}
- guard.release();
}
private static String threadName() {
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.ListeningExecutorService;
+import com.google.common.util.concurrent.MoreExecutors;
import com.google.common.util.concurrent.ThreadFactoryBuilder;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import org.junit.After;
import org.junit.Before;
@Before
public void setUp() {
- syncThreadPool = FrmExecutors.instance()
- .newFixedThreadPool(1, new ThreadFactoryBuilder()
- .setNameFormat(SyncReactorFutureDecorator.FRM_RPC_CLIENT_PREFIX + "%d")
- .setDaemon(false)
- .build());
-
+ final ExecutorService executorService = Executors.newSingleThreadExecutor(new ThreadFactoryBuilder()
+ .setDaemon(false)
+ .setNameFormat("frsync-test%d")
+ .setUncaughtExceptionHandler((thread, e) -> LOG.error("Uncaught exception {}", thread, e))
+ .build());
+ syncThreadPool = MoreExecutors.listeningDecorator(executorService);
reactor = new SyncReactorFutureZipDecorator(delegate, syncThreadPool);
fcNodePath = InstanceIdentifier.create(Nodes.class).child(Node.class, new NodeKey(NODE_ID))
.augmentation(FlowCapableNode.class);
package org.opendaylight.openflowplugin.applications.notification.supplier;
-import org.opendaylight.controller.md.sal.binding.api.DataChangeListener;
+import org.opendaylight.controller.md.sal.binding.api.DataTreeChangeListener;
import org.opendaylight.yangtools.yang.binding.DataObject;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
*
* @param <O> - {@link DataObject} represent Data Tree Item from DataStore
*/
-public interface NotificationSupplierDefinition<O extends DataObject> extends AutoCloseable, DataChangeListener {
+public interface NotificationSupplierDefinition<O extends DataObject> extends AutoCloseable, DataTreeChangeListener<O> {
/**
* Method return wildCardPath for Listener registration and for identify
* @return {@link InstanceIdentifier}
*/
InstanceIdentifier<O> getWildCardPath();
+
}
import com.google.common.base.Preconditions;
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
-import org.opendaylight.controller.md.sal.binding.api.DataChangeListener;
+import org.opendaylight.controller.md.sal.binding.api.DataTreeChangeListener;
+import org.opendaylight.controller.md.sal.binding.api.DataTreeIdentifier;
import org.opendaylight.controller.md.sal.common.api.data.AsyncDataBroker.DataChangeScope;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
import org.opendaylight.openflowplugin.applications.notification.supplier.NotificationSupplierDefinition;
NotificationSupplierDefinition<O> {
protected final Class<O> clazz;
- private ListenerRegistration<DataChangeListener> listenerRegistration;
+ private ListenerRegistration<DataTreeChangeListener> listenerRegistration;
/**
* Default constructor for all Notification Supplier implementation
*/
public AbstractNotificationSupplierBase(final DataBroker db, final Class<O> clazz) {
Preconditions.checkArgument(db != null, "DataBroker can not be null!");
- listenerRegistration = db.registerDataChangeListener(LogicalDatastoreType.OPERATIONAL, getWildCardPath(), this,
- DataChangeScope.BASE);
+ //TODO retries
+ listenerRegistration = db.registerDataTreeChangeListener( new DataTreeIdentifier<>(LogicalDatastoreType.OPERATIONAL,
+ getWildCardPath()),this);
this.clazz = clazz;
}
package org.opendaylight.openflowplugin.applications.notification.supplier.impl;
import com.google.common.base.Preconditions;
+
+import java.util.Collection;
import java.util.Map.Entry;
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+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.AsyncDataChangeEvent;
import org.opendaylight.controller.sal.binding.api.NotificationProviderService;
import org.opendaylight.openflowplugin.applications.notification.supplier.NotificationSupplierForItemRoot;
}
@Override
- public void onDataChanged(final AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> change) {
- Preconditions.checkArgument(change != null, "ChangeEvent can not be null!");
- if (change.getCreatedData() != null && ! (change.getCreatedData().isEmpty())) {
- for (final Entry<InstanceIdentifier<?>, DataObject> createDataObj : change.getCreatedData().entrySet()) {
- if (clazz.isAssignableFrom(createDataObj.getKey().getTargetType())) {
- final InstanceIdentifier<O> ii = createDataObj.getKey().firstIdentifierOf(clazz);
- final C notif = createNotification((O) createDataObj.getValue(), ii);
- if (notif != null) {
- notificationProviderService.publish(notif);
+ public void onDataTreeChanged(Collection<DataTreeModification<O>> changes) {
+
+ Preconditions.checkNotNull(changes, "Changes may not be null!");
+
+ for (DataTreeModification<O> change : changes) {
+ final InstanceIdentifier<O> key = change.getRootPath().getRootIdentifier();
+ final DataObjectModification<O> mod = change.getRootNode();
+ switch (mod.getModificationType()) {
+ case DELETE:
+ remove(key, mod.getDataBefore());
+ break;
+ case SUBTREE_MODIFIED:
+ update(key, mod.getDataBefore(), mod.getDataAfter());
+ break;
+ case WRITE:
+ if (mod.getDataBefore() == null) {
+ add(key, mod.getDataAfter());
+ } else {
+ update(key, mod.getDataBefore(), mod.getDataAfter());
}
- }
+ break;
+ default:
+ throw new IllegalArgumentException("Unhandled modification type " + mod.getModificationType());
}
}
+ }
- if (change.getRemovedPaths() != null && !(change.getRemovedPaths().isEmpty())) {
- for (final InstanceIdentifier<?> deleteDataPath : change.getRemovedPaths()) {
- if (clazz.isAssignableFrom(deleteDataPath.getTargetType())) {
- final D notif = deleteNotification(deleteDataPath.firstIdentifierOf(clazz));
- if (notif != null) {
- notificationProviderService.publish(notif);
- }
- }
- }
+
+ public void add(InstanceIdentifier<O> identifier , O add ){
+
+ final C notif = createNotification(add, identifier);
+ if (notif != null) {
+ notificationProviderService.publish(notif);
+ }
+ }
+
+ public void remove(InstanceIdentifier<O> identifier , O del){
+ final D notif = deleteNotification(identifier.firstIdentifierOf(clazz));
+ if (notif != null) {
+ notificationProviderService.publish(notif);
}
}
+
+ public void update(InstanceIdentifier<O> identifier , O before, O after){
+ //EMPTY NO-OP
+ }
+
}
package org.opendaylight.openflowplugin.applications.notification.supplier.impl.item;
import com.google.common.base.Preconditions;
+
+import java.util.Collection;
import java.util.Map.Entry;
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+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.AsyncDataChangeEvent;
import org.opendaylight.controller.sal.binding.api.NotificationProviderService;
import org.opendaylight.openflowplugin.applications.notification.supplier.NotificationSupplierForItem;
}
@Override
- public void onDataChanged(final AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> change) {
- Preconditions.checkArgument(change != null, "ChangeEvent can not be null!");
- if (change.getCreatedData() != null && !(change.getCreatedData().isEmpty())) {
- for (final Entry<InstanceIdentifier<?>, DataObject> createDataObj : change.getCreatedData().entrySet()) {
- if (clazz.isAssignableFrom(createDataObj.getKey().getTargetType())) {
- final InstanceIdentifier<O> ii = createDataObj.getKey().firstIdentifierOf(clazz);
- final C notif = createNotification((O) createDataObj.getValue(), ii);
- if (notif != null) {
- notificationProviderService.publish(notif);
+ public void onDataTreeChanged(Collection<DataTreeModification<O>> changes) {
+
+ Preconditions.checkNotNull(changes, "Changes may not be null!");
+
+ for (DataTreeModification<O> change : changes) {
+ final InstanceIdentifier<O> key = change.getRootPath().getRootIdentifier();
+ final DataObjectModification<O> mod = change.getRootNode();
+ switch (mod.getModificationType()) {
+ case DELETE:
+ remove(key, mod.getDataBefore());
+ break;
+ case SUBTREE_MODIFIED:
+ update(key, mod.getDataBefore(), mod.getDataAfter());
+ break;
+ case WRITE:
+ if (mod.getDataBefore() == null) {
+ add(key, mod.getDataAfter());
+ } else {
+ update(key, mod.getDataBefore(), mod.getDataAfter());
}
- }
+ break;
+ default:
+ throw new IllegalArgumentException("Unhandled modification type " + mod.getModificationType());
}
}
+ }
- if (change.getUpdatedData() != null && !(change.getUpdatedData().isEmpty())) {
- for (final Entry<InstanceIdentifier<?>, DataObject> updateDataObj : change.getUpdatedData().entrySet()) {
- if (clazz.isAssignableFrom(updateDataObj.getKey().getTargetType())) {
- final InstanceIdentifier<O> ii = updateDataObj.getKey().firstIdentifierOf(clazz);
- final U notif = updateNotification((O) updateDataObj.getValue(), ii);
- if (notif != null) {
- notificationProviderService.publish(notif);
- }
- }
- }
+
+ public void add(InstanceIdentifier<O> identifier , O add ){
+ final C notif = createNotification(add, identifier);
+ if (notif != null) {
+ notificationProviderService.publish(notif);
}
+ }
- if (change.getRemovedPaths() != null && !(change.getRemovedPaths().isEmpty())) {
- for (final InstanceIdentifier<?> deleteDataPath : change.getRemovedPaths()) {
- if (clazz.isAssignableFrom(deleteDataPath.getTargetType())) {
- final D notif = deleteNotification(deleteDataPath.firstIdentifierOf(clazz));
- if (notif != null) {
- notificationProviderService.publish(notif);
- }
- }
- }
+
+ public void remove(InstanceIdentifier<O> identifier , O del){
+ final D notif = deleteNotification(identifier.firstIdentifierOf(clazz));
+ if (notif != null) {
+ notificationProviderService.publish(notif);
+ }
+ }
+
+
+ public void update(InstanceIdentifier<O> identifier , O before, O after){
+
+ final U notif = updateNotification(after, identifier);
+ if (notif != null) {
+ notificationProviderService.publish(notif);
}
}
+
}
package org.opendaylight.openflowplugin.applications.notification.supplier.impl.item.stat;
import com.google.common.base.Preconditions;
+
+import java.util.Collection;
import java.util.Map.Entry;
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+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.AsyncDataChangeEvent;
import org.opendaylight.controller.sal.binding.api.NotificationProviderService;
import org.opendaylight.openflowplugin.applications.notification.supplier.NotificationSupplierForItemStat;
}
@Override
- public void onDataChanged(final AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> change) {
- Preconditions.checkArgument(change != null, "ChangeEvent can not be null!");
- if (change.getCreatedData() != null && !(change.getCreatedData().isEmpty())) {
- for (final Entry<InstanceIdentifier<?>, DataObject> createDataObj : change.getCreatedData().entrySet()) {
- if (clazz.isAssignableFrom(createDataObj.getKey().getTargetType())) {
- final InstanceIdentifier<O> ii = createDataObj.getKey().firstIdentifierOf(clazz);
- final N notif = createNotification((O) createDataObj.getValue(), ii);
- if (notif != null) {
- notifProviderService.publish(notif);
+ public void onDataTreeChanged(Collection<DataTreeModification<O>> changes) {
+
+ Preconditions.checkNotNull(changes, "Changes may not be null!");
+
+ for (DataTreeModification<O> change : changes) {
+ final InstanceIdentifier<O> key = change.getRootPath().getRootIdentifier();
+ final DataObjectModification<O> mod = change.getRootNode();
+ switch (mod.getModificationType()) {
+ case DELETE:
+ remove(key, mod.getDataBefore());
+ break;
+ case SUBTREE_MODIFIED:
+ update(key, mod.getDataBefore(), mod.getDataAfter());
+ break;
+ case WRITE:
+ if (mod.getDataBefore() == null) {
+ add(key, mod.getDataAfter());
+ } else {
+ update(key, mod.getDataBefore(), mod.getDataAfter());
}
- }
+ break;
+ default:
+ throw new IllegalArgumentException("Unhandled modification type " + mod.getModificationType());
}
}
}
+
+
+ public void add(InstanceIdentifier<O> identifier , O add ){
+ final N notif = createNotification(add, identifier);
+ if (notif != null) {
+ notifProviderService.publish(notif);
+ }
+ }
+
+
+ public void remove(InstanceIdentifier<O> identifier , O del){
+ //EMPTY NO-OP
+ }
+
+
+ public void update(InstanceIdentifier<O> identifier , O before, O after){
+ //EMPTY NO-OP
+ }
+
}
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
+import java.util.ArrayList;
+import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
+
import org.junit.Before;
import org.junit.Test;
import org.mockito.Matchers;
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import org.opendaylight.controller.md.sal.binding.api.DataObjectModification;
+import org.opendaylight.controller.md.sal.binding.api.DataTreeModification;
import org.opendaylight.controller.sal.binding.api.NotificationProviderService;
import org.opendaylight.openflowplugin.applications.notification.supplier.impl.helper.TestChangeEventBuildHelper;
+import org.opendaylight.openflowplugin.applications.notification.supplier.impl.helper.TestData;
import org.opendaylight.openflowplugin.applications.notification.supplier.impl.helper.TestSupplierVerifyHelper;
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.inventory.rev130819.tables.table.Flow;
import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorId;
import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorRemoved;
import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorUpdated;
*/
public class NodeConnectorNotificationSupplierImplTest {
- private static final String FLOW_NODE_ID = "test-111";
+ private static final String FLOW_NODE_ID = "openflow:111";
private static final String FLOW_CODE_CONNECTOR_ID = "test-con-111";
private NodeConnectorNotificationSupplierImpl notifSupplierImpl;
private NotificationProviderService notifProviderService;
TestSupplierVerifyHelper.verifyDataChangeRegistration(dataBroker);
}
- @Test(expected = IllegalArgumentException.class)
+ @Test(expected = NullPointerException.class)
public void testNullChangeEvent() {
- notifSupplierImpl.onDataChanged(null);
+ notifSupplierImpl.onDataTreeChanged(null);
}
- @Test
+ @Test(expected = NullPointerException.class)
public void testNullableChangeEvent() {
- notifSupplierImpl.onDataChanged(TestChangeEventBuildHelper.createEmptyTestDataEvent());
+ notifSupplierImpl.onDataTreeChanged(TestChangeEventBuildHelper.createNullTestDataTreeEvent());
}
@Test
public void testEmptyChangeEvent() {
- notifSupplierImpl.onDataChanged(TestChangeEventBuildHelper.createEmptyTestDataEvent());
+ notifSupplierImpl.onDataTreeChanged( TestChangeEventBuildHelper.createEmptyTestDataTreeEvent());
}
@Test
@Test
public void testCreateChangeEvent() {
- final Map<InstanceIdentifier<?>, DataObject> createdData = new HashMap<>();
- createdData.put(createTestFlowCapableConnectorNodePath(), createTestFlowCapableNodeConnecor());
- notifSupplierImpl.onDataChanged(TestChangeEventBuildHelper.createTestDataEvent(createdData, null, null));
+ final TestData testData = new TestData(createTestFlowCapableConnectorNodePath(),null,
+ createTestFlowCapableNodeConnecor(),DataObjectModification.ModificationType.WRITE);
+ Collection<DataTreeModification<FlowCapableNodeConnector>> collection = new ArrayList<>();
+ collection.add(testData);
+ notifSupplierImpl.onDataTreeChanged(collection);
verify(notifProviderService, times(1)).publish(Matchers.any(NodeConnectorUpdated.class));
}
@Test
public void testDeleteChangeEvent() {
- final Set<InstanceIdentifier<?>> removeData = new HashSet<>();
- removeData.add(createTestFlowCapableConnectorNodePath());
- notifSupplierImpl.onDataChanged(TestChangeEventBuildHelper.createTestDataEvent(null, null, removeData));
+ final TestData testData = new TestData(createTestFlowCapableConnectorNodePath(),
+ createTestFlowCapableNodeConnecor(),null,DataObjectModification.ModificationType.DELETE);
+ Collection<DataTreeModification<FlowCapableNodeConnector>> collection = new ArrayList<>();
+ collection.add(testData);
+ notifSupplierImpl.onDataTreeChanged(collection);
verify(notifProviderService, times(1)).publish(Matchers.any(NodeConnectorRemoved.class));
}
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
+import java.util.ArrayList;
+import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
+
import org.junit.Before;
import org.junit.Test;
import org.mockito.Matchers;
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import org.opendaylight.controller.md.sal.binding.api.DataObjectModification;
+import org.opendaylight.controller.md.sal.binding.api.DataTreeModification;
import org.opendaylight.controller.sal.binding.api.NotificationProviderService;
import org.opendaylight.openflowplugin.applications.notification.supplier.impl.helper.TestChangeEventBuildHelper;
+import org.opendaylight.openflowplugin.applications.notification.supplier.impl.helper.TestData;
import org.opendaylight.openflowplugin.applications.notification.supplier.impl.helper.TestSupplierVerifyHelper;
import org.opendaylight.openflowplugin.applications.notification.supplier.impl.helper.TestSupplierVerifyHelper;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNodeBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNodeConnector;
import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRemoved;
import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeUpdated;
*/
public class NodeNotificationSupplierImplTest {
- private static final String FLOW_NODE_ID = "test-111";
+ private static final String FLOW_NODE_ID = "openflow:111";
private NodeNotificationSupplierImpl notifSupplierImpl;
private NotificationProviderService notifProviderService;
private DataBroker dataBroker;
TestSupplierVerifyHelper.verifyDataChangeRegistration(dataBroker);
}
- @Test(expected = IllegalArgumentException.class)
+ @Test(expected = NullPointerException.class)
public void testNullChangeEvent() {
- notifSupplierImpl.onDataChanged(null);
+ notifSupplierImpl.onDataTreeChanged(null);
}
- @Test
+ @Test(expected = NullPointerException.class)
public void testNullableChangeEvent() {
- notifSupplierImpl.onDataChanged(TestChangeEventBuildHelper.createEmptyTestDataEvent());
+ notifSupplierImpl.onDataTreeChanged( TestChangeEventBuildHelper.createNullTestDataTreeEvent());
}
@Test
public void testEmptyChangeEvent() {
- notifSupplierImpl.onDataChanged(TestChangeEventBuildHelper.createEmptyTestDataEvent());
+ notifSupplierImpl.onDataTreeChanged(TestChangeEventBuildHelper.createEmptyTestDataTreeEvent());
}
@Test
@Test
public void testCreateChangeEvent() {
- final Map<InstanceIdentifier<?>, DataObject> createdData = new HashMap<>();
- createdData.put(createTestFlowCapableNodePath(), createTestFlowCapableNode());
- notifSupplierImpl.onDataChanged(TestChangeEventBuildHelper.createTestDataEvent(createdData, null, null));
+ final TestData testData = new TestData(createTestFlowCapableNodePath(),null,
+ createTestFlowCapableNode(), DataObjectModification.ModificationType.WRITE);
+ Collection<DataTreeModification<FlowCapableNode>> collection = new ArrayList<>();
+ collection.add(testData);
+ notifSupplierImpl.onDataTreeChanged(collection);
verify(notifProviderService, times(1)).publish(Matchers.any(NodeUpdated.class));
}
@Test
public void testDeleteChangeEvent() {
- final Set<InstanceIdentifier<?>> removeData = new HashSet<>();
- removeData.add(createTestFlowCapableNodePath());
- notifSupplierImpl.onDataChanged(TestChangeEventBuildHelper.createTestDataEvent(null, null, removeData));
+ final TestData testData = new TestData(createTestFlowCapableNodePath(),
+ createTestFlowCapableNode(),null, DataObjectModification.ModificationType.DELETE);
+ Collection<DataTreeModification<FlowCapableNode>> collection = new ArrayList<>();
+ collection.add(testData);
+ notifSupplierImpl.onDataTreeChanged(collection);
verify(notifProviderService, times(1)).publish(Matchers.any(NodeRemoved.class));
}
package org.opendaylight.openflowplugin.applications.notification.supplier.impl.helper;
import static org.mockito.Mockito.mock;
+import java.util.Collection;
import java.util.Collections;
import java.util.Map;
import java.util.Set;
+
+import org.opendaylight.controller.md.sal.binding.api.DataTreeModification;
import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent;
import org.opendaylight.yangtools.yang.binding.DataObject;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
throw new UnsupportedOperationException("Test utility class");
}
- public static AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> createTestDataEvent(
- final Map<InstanceIdentifier<?>, DataObject> createdData,
- final Map<InstanceIdentifier<?>, DataObject> updatedData,
- final Set<InstanceIdentifier<?>> removedData) {
- return new AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject>() {
-
- @Override
- public DataObject getUpdatedSubtree() {
- return mock(DataObject.class);
- }
-
- @Override
- public Map<InstanceIdentifier<?>, DataObject> getUpdatedData() {
- if (updatedData != null) {
- return Collections.unmodifiableMap(updatedData);
- } else {
- return Collections.emptyMap();
- }
- }
-
- @Override
- public Set<InstanceIdentifier<?>> getRemovedPaths() {
- if (removedData != null) {
- return Collections.unmodifiableSet(removedData);
- } else {
- return Collections.emptySet();
- }
- }
-
- @Override
- public DataObject getOriginalSubtree() {
- return mock(DataObject.class);
- }
-
- @Override
- public Map<InstanceIdentifier<?>, DataObject> getOriginalData() {
- return Collections.emptyMap();
- }
-
- @Override
- public Map<InstanceIdentifier<?>, DataObject> getCreatedData() {
- if (createdData != null) {
- return Collections.unmodifiableMap(createdData);
- } else {
- return Collections.emptyMap();
- }
- }
- };
+ public static Collection createEmptyTestDataTreeEvent(){
+ return Collections.EMPTY_LIST ;
}
- public static AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> createEmptyTestDataEvent() {
- return new AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject>() {
-
- @Override
- public DataObject getUpdatedSubtree() {
- return mock(DataObject.class);
- }
-
- @Override
- public Map<InstanceIdentifier<?>, DataObject> getUpdatedData() {
- return Collections.emptyMap();
- }
-
- @Override
- public Set<InstanceIdentifier<?>> getRemovedPaths() {
- return Collections.emptySet();
- }
-
- @Override
- public DataObject getOriginalSubtree() {
- return mock(DataObject.class);
- }
-
- @Override
- public Map<InstanceIdentifier<?>, DataObject> getOriginalData() {
- return Collections.emptyMap();
- }
-
- @Override
- public Map<InstanceIdentifier<?>, DataObject> getCreatedData() {
- return Collections.emptyMap();
- }
- };
+ public static Collection createNullTestDataTreeEvent(){
+ return null;
}
- public static AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> createNullTestDataEvent() {
- return new AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject>() {
-
- @Override
- public DataObject getUpdatedSubtree() {
- return null;
- }
-
- @Override
- public Map<InstanceIdentifier<?>, DataObject> getUpdatedData() {
- return null;
- }
-
- @Override
- public Set<InstanceIdentifier<?>> getRemovedPaths() {
- return null;
- }
-
- @Override
- public DataObject getOriginalSubtree() {
- return null;
- }
-
- @Override
- public Map<InstanceIdentifier<?>, DataObject> getOriginalData() {
- return null;
- }
-
- @Override
- public Map<InstanceIdentifier<?>, DataObject> getCreatedData() {
- return null;
- }
- };
- }
}
--- /dev/null
+/*
+ * Copyright (c) 2016 Ericsson 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.notification.supplier.impl.helper;
+
+import org.opendaylight.controller.md.sal.binding.api.DataObjectModification;
+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.yangtools.yang.binding.*;
+
+
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+import java.util.Collection;
+
+/**
+ * Created by eshuvka on 6/7/2016.
+ */
+public class TestData<T extends DataObject> implements DataTreeModification<T> {
+
+ private final DataTreeIdentifier<T> path;
+ private final DataObjectModification<T> rootNode;
+
+ public TestData (final InstanceIdentifier<T> path, final T dataBefore, final T dataAfter,DataObjectModification.ModificationType modType) {
+ this.path = new DataTreeIdentifier<>(LogicalDatastoreType.CONFIGURATION, path);
+ this.rootNode = new Test(dataBefore, dataAfter, modType);
+ }
+
+ @Nonnull
+ @Override
+ public DataTreeIdentifier<T> getRootPath() {
+ return path;
+ }
+
+ @Nonnull
+ @Override
+ public DataObjectModification<T> getRootNode() {
+ return rootNode;
+ }
+}
+
+class Test <T extends DataObject> implements DataObjectModification<T>{
+
+ private final T dataObjBefore;
+ private final T dataObjAfter;
+ private final ModificationType modification;
+
+ Test(final T dataBefore,final T dataAfter, ModificationType modType){
+ dataObjBefore = dataBefore;
+ dataObjAfter = dataAfter;
+ modification = modType;
+ }
+
+ @Override
+ public InstanceIdentifier.PathArgument getIdentifier() {
+ return null;
+ }
+
+ @Nonnull
+ @Override
+ public Class<T> getDataType() {
+ return null;
+ }
+
+ @Nonnull
+ @Override
+ public ModificationType getModificationType() {
+ return modification;
+ }
+
+ @Nullable
+ @Override
+ public T getDataBefore() {
+ return dataObjBefore;
+ }
+
+ @Nullable
+ @Override
+ public T getDataAfter() {
+ return dataObjAfter;
+ }
+
+ @Nonnull
+ @Override
+ public Collection<DataObjectModification<? extends DataObject>> getModifiedChildren() {
+ return null;
+ }
+
+ @Nullable
+ @Override
+ public <C extends ChildOf<? super T>> DataObjectModification<C> getModifiedChildContainer(@Nonnull Class<C> aClass) {
+ return null;
+ }
+
+ @Nullable
+ @Override
+ public <C extends Augmentation<T> & DataObject> DataObjectModification<C> getModifiedAugmentation(@Nonnull Class<C> aClass) {
+ return null;
+ }
+
+ @Override
+ public <C extends Identifiable<K> & ChildOf<? super T>, K extends Identifier<C>> DataObjectModification<C> getModifiedChildListItem(@Nonnull Class<C> aClass, @Nonnull K k) {
+ return null;
+ }
+
+ @Nullable
+ @Override
+ public DataObjectModification<? extends DataObject> getModifiedChild(InstanceIdentifier.PathArgument pathArgument) {
+ return null;
+ }
+}
import org.mockito.Mockito;
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
import org.opendaylight.controller.md.sal.binding.api.DataChangeListener;
+import org.opendaylight.controller.md.sal.binding.api.DataTreeChangeListener;
+import org.opendaylight.controller.md.sal.binding.api.DataTreeIdentifier;
import org.opendaylight.controller.md.sal.common.api.data.AsyncDataBroker;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
* @param dataBroker
*/
public static void verifyDataChangeRegistration(DataBroker dataBroker) {
- Mockito.verify(dataBroker).registerDataChangeListener(
- Matchers.eq(LogicalDatastoreType.OPERATIONAL),
- Matchers.notNull(InstanceIdentifier.class),
- Matchers.notNull(DataChangeListener.class),
- Matchers.eq(AsyncDataBroker.DataChangeScope.BASE));
+
+ Mockito.verify(dataBroker).registerDataTreeChangeListener(
+ Matchers.<DataTreeIdentifier>any(),
+ Matchers.<DataTreeChangeListener>any());
+
+
}
}
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
+import java.util.ArrayList;
+import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import org.junit.Test;
import org.mockito.Matchers;
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import org.opendaylight.controller.md.sal.binding.api.DataObjectModification;
+import org.opendaylight.controller.md.sal.binding.api.DataTreeModification;
import org.opendaylight.controller.sal.binding.api.NotificationProviderService;
import org.opendaylight.openflowplugin.applications.notification.supplier.impl.helper.TestChangeEventBuildHelper;
+import org.opendaylight.openflowplugin.applications.notification.supplier.impl.helper.TestData;
import org.opendaylight.openflowplugin.applications.notification.supplier.impl.helper.TestSupplierVerifyHelper;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowId;
*/
public class FlowNotificationSupplierImplTest {
- private static final String FLOW_NODE_ID = "test-111";
+ private static final String FLOW_NODE_ID = "openflow:111";
private static final Short FLOW_TABLE_ID = 111;
+ private static final Short UPDATED_FLOW_TABLE_ID = 100;
private static final String FLOW_ID = "test-flow-111";
+ private static final String UPDATED_FLOW_ID = "test-flow-100";
private FlowNotificationSupplierImpl notifSupplierImpl;
private NotificationProviderService notifProviderService;
private DataBroker dataBroker;
TestSupplierVerifyHelper.verifyDataChangeRegistration(dataBroker);
}
- @Test(expected = IllegalArgumentException.class)
+ @Test(expected = NullPointerException.class)
public void testNullChangeEvent() {
- notifSupplierImpl.onDataChanged(null);
+ notifSupplierImpl.onDataTreeChanged(null);
}
- @Test
+ @Test(expected = NullPointerException.class)
public void testNullableChangeEvent() {
- notifSupplierImpl.onDataChanged(TestChangeEventBuildHelper.createEmptyTestDataEvent());
+ notifSupplierImpl.onDataTreeChanged(TestChangeEventBuildHelper.createNullTestDataTreeEvent());
}
@Test
public void testEmptyChangeEvent() {
- notifSupplierImpl.onDataChanged(TestChangeEventBuildHelper.createEmptyTestDataEvent());
+ notifSupplierImpl.onDataTreeChanged(TestChangeEventBuildHelper.createEmptyTestDataTreeEvent());
}
@Test
@Test
public void testCreateChangeEvent() {
- final Map<InstanceIdentifier<?>, DataObject> createdData = new HashMap<>();
- createdData.put(createTestFlowPath(), createTestFlow());
- notifSupplierImpl.onDataChanged(TestChangeEventBuildHelper.createTestDataEvent(createdData, null, null));
+ final TestData testData = new TestData(createTestFlowPath(),null,createTestFlow(),
+ DataObjectModification.ModificationType.WRITE);
+ Collection<DataTreeModification<Flow>> collection = new ArrayList<>();
+ collection.add(testData);
+ notifSupplierImpl.onDataTreeChanged(collection);
verify(notifProviderService, times(1)).publish(Matchers.any(FlowAdded.class));
}
@Test
public void testUpdateChangeEvent() {
- final Map<InstanceIdentifier<?>, DataObject> createdData = new HashMap<>();
- createdData.put(createTestFlowPath(), createTestFlow());
- notifSupplierImpl.onDataChanged(TestChangeEventBuildHelper.createTestDataEvent(createdData, null, null));
+ final TestData testData = new TestData(createTestFlowPath(),createTestFlow(),createUpdatedTestFlow(),
+ DataObjectModification.ModificationType.SUBTREE_MODIFIED);
+ Collection<DataTreeModification<Flow>> collection = new ArrayList<>();
+ collection.add(testData);
+ notifSupplierImpl.onDataTreeChanged(collection);
verify(notifProviderService, times(1)).publish(Matchers.any(FlowUpdated.class));
}
@Test
public void testDeleteChangeEvent() {
- final Set<InstanceIdentifier<?>> removeData = new HashSet<>();
- removeData.add(createTestFlowPath());
- notifSupplierImpl.onDataChanged(TestChangeEventBuildHelper.createTestDataEvent(null, null, removeData));
+ final TestData testData = new TestData(createTestFlowPath(),createTestFlow(),null,
+ DataObjectModification.ModificationType.DELETE);
+ Collection<DataTreeModification<Flow>> collection = new ArrayList<>();
+ collection.add(testData);
+ notifSupplierImpl.onDataTreeChanged(collection);
verify(notifProviderService, times(1)).publish(Matchers.any(FlowRemoved.class));
}
builder.setTableId(FLOW_TABLE_ID);
return builder.build();
}
+
+ private static Flow createUpdatedTestFlow(){
+ final FlowBuilder builder = new FlowBuilder();
+ builder.setId(new FlowId(UPDATED_FLOW_ID));
+ builder.setTableId(UPDATED_FLOW_TABLE_ID);
+ return builder.build();
+ }
}
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
+import java.util.ArrayList;
+import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import org.junit.Test;
import org.mockito.Matchers;
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import org.opendaylight.controller.md.sal.binding.api.DataObjectModification;
+import org.opendaylight.controller.md.sal.binding.api.DataTreeModification;
import org.opendaylight.controller.sal.binding.api.NotificationProviderService;
import org.opendaylight.openflowplugin.applications.notification.supplier.impl.helper.TestChangeEventBuildHelper;
+import org.opendaylight.openflowplugin.applications.notification.supplier.impl.helper.TestData;
import org.opendaylight.openflowplugin.applications.notification.supplier.impl.helper.TestSupplierVerifyHelper;
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.Flow;
import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.GroupAdded;
import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.GroupRemoved;
import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.GroupUpdated;
*/
public class GroupNotificationSupplierImplTest {
- private static final String FLOW_NODE_ID = "test-111";
+ private static final String FLOW_NODE_ID = "openflow:111";
private static final Long GROUP_ID = 111L;
+ private static final Long UPDATED_GROUP_ID = 100L;
+
private GroupNotificationSupplierImpl notifSupplierImpl;
private NotificationProviderService notifProviderService;
private DataBroker dataBroker;
TestSupplierVerifyHelper.verifyDataChangeRegistration(dataBroker);
}
- @Test(expected = IllegalArgumentException.class)
+ @Test(expected = NullPointerException.class)
public void testNullChangeEvent() {
- notifSupplierImpl.onDataChanged(null);
+ notifSupplierImpl.onDataTreeChanged(null);
}
- @Test
+ @Test(expected = NullPointerException.class)
public void testNullableChangeEvent() {
- notifSupplierImpl.onDataChanged(TestChangeEventBuildHelper.createEmptyTestDataEvent());
+ notifSupplierImpl.onDataTreeChanged( TestChangeEventBuildHelper.createNullTestDataTreeEvent());
}
@Test
public void testEmptyChangeEvent() {
- notifSupplierImpl.onDataChanged(TestChangeEventBuildHelper.createEmptyTestDataEvent());
+ notifSupplierImpl.onDataTreeChanged( TestChangeEventBuildHelper.createEmptyTestDataTreeEvent());
}
@Test
@Test
public void testCreateChangeEvent() {
- final Map<InstanceIdentifier<?>, DataObject> createdData = new HashMap<>();
- createdData.put(createTestGroupPath(), createTestGroup());
- notifSupplierImpl.onDataChanged(TestChangeEventBuildHelper.createTestDataEvent(createdData, null, null));
+ final TestData testData = new TestData(createTestGroupPath(),null,createTestGroup(),
+ DataObjectModification.ModificationType.WRITE);
+ Collection<DataTreeModification<Group>> collection = new ArrayList<>();
+ collection.add(testData);
+ notifSupplierImpl.onDataTreeChanged(collection);
verify(notifProviderService, times(1)).publish(Matchers.any(GroupAdded.class));
}
@Test
public void testUpdateChangeEvent() {
- final Map<InstanceIdentifier<?>, DataObject> createdData = new HashMap<>();
- createdData.put(createTestGroupPath(), createTestGroup());
- notifSupplierImpl.onDataChanged(TestChangeEventBuildHelper.createTestDataEvent(createdData, null, null));
+ final TestData testData = new TestData(createTestGroupPath(),createTestGroup(),createUpdatedTestGroup(),
+ DataObjectModification.ModificationType.SUBTREE_MODIFIED);
+ Collection<DataTreeModification<Group>> collection = new ArrayList<>();
+ collection.add(testData);
+ notifSupplierImpl.onDataTreeChanged(collection);
verify(notifProviderService, times(1)).publish(Matchers.any(GroupUpdated.class));
}
@Test
public void testDeleteChangeEvent() {
- final Set<InstanceIdentifier<?>> removeData = new HashSet<>();
- removeData.add(createTestGroupPath());
- notifSupplierImpl.onDataChanged(TestChangeEventBuildHelper.createTestDataEvent(null, null, removeData));
+ final TestData testData = new TestData(createTestGroupPath(),createTestGroup(),null,
+ DataObjectModification.ModificationType.DELETE);
+ Collection<DataTreeModification<Group>> collection = new ArrayList<>();
+ collection.add(testData);
+ notifSupplierImpl.onDataTreeChanged(collection);
verify(notifProviderService, times(1)).publish(Matchers.any(GroupRemoved.class));
}
builder.setGroupId(new GroupId(GROUP_ID));
return builder.build();
}
+
+ private static Group createUpdatedTestGroup() {
+ final GroupBuilder builder = new GroupBuilder();
+ builder.setGroupId(new GroupId(UPDATED_GROUP_ID));
+ return builder.build();
+ }
+
}
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
+import java.util.ArrayList;
+import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
+
import org.junit.Before;
import org.junit.Test;
import org.mockito.Matchers;
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import org.opendaylight.controller.md.sal.binding.api.DataObjectModification;
+import org.opendaylight.controller.md.sal.binding.api.DataTreeModification;
import org.opendaylight.controller.sal.binding.api.NotificationProviderService;
import org.opendaylight.openflowplugin.applications.notification.supplier.impl.helper.TestChangeEventBuildHelper;
+import org.opendaylight.openflowplugin.applications.notification.supplier.impl.helper.TestData;
import org.opendaylight.openflowplugin.applications.notification.supplier.impl.helper.TestSupplierVerifyHelper;
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;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.meters.MeterBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.meters.MeterKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.GroupUpdated;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.groups.Group;
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;
*/
public class MeterNotificationSupplierImplTest {
- private static final String FLOW_NODE_ID = "test-111";
+ private static final String FLOW_NODE_ID = "openfow:111";
private static final Long METER_ID = 111L;
+ private static final Long UPDATED_METER_ID = 100L;
+
private MeterNotificationSupplierImpl notifSupplierImpl;
private NotificationProviderService notifProviderService;
private DataBroker dataBroker;
TestSupplierVerifyHelper.verifyDataChangeRegistration(dataBroker);
}
- @Test(expected = IllegalArgumentException.class)
+ @Test(expected = NullPointerException.class)
public void testNullChangeEvent() {
- notifSupplierImpl.onDataChanged(null);
+ notifSupplierImpl.onDataTreeChanged(null);
}
- @Test
+ @Test(expected = NullPointerException.class)
public void testNullableChangeEvent() {
- notifSupplierImpl.onDataChanged(TestChangeEventBuildHelper.createEmptyTestDataEvent());
+ notifSupplierImpl.onDataTreeChanged(TestChangeEventBuildHelper.createNullTestDataTreeEvent());
}
@Test
public void testEmptyChangeEvent() {
- notifSupplierImpl.onDataChanged(TestChangeEventBuildHelper.createEmptyTestDataEvent());
+ notifSupplierImpl.onDataTreeChanged(TestChangeEventBuildHelper.createEmptyTestDataTreeEvent());
}
@Test
@Test
public void testCreateChangeEvent() {
- final Map<InstanceIdentifier<?>, DataObject> createdData = new HashMap<>();
- createdData.put(createTestMeterPath(), createTestMeter());
- notifSupplierImpl.onDataChanged(TestChangeEventBuildHelper.createTestDataEvent(createdData, null, null));
+ final TestData testData = new TestData(createTestMeterPath(),null,createTestMeter(),
+ DataObjectModification.ModificationType.WRITE);
+ Collection<DataTreeModification<Meter>> collection = new ArrayList<>();
+ collection.add(testData);
+ notifSupplierImpl.onDataTreeChanged(collection);
verify(notifProviderService, times(1)).publish(Matchers.any(MeterAdded.class));
}
@Test
public void testUdateChangeEvent() {
- final Map<InstanceIdentifier<?>, DataObject> createdData = new HashMap<>();
- createdData.put(createTestMeterPath(), createTestMeter());
- notifSupplierImpl.onDataChanged(TestChangeEventBuildHelper.createTestDataEvent(createdData, null, null));
+ final TestData testData = new TestData(createTestMeterPath(),createTestMeter(),createUpdatedTestMeter(),
+ DataObjectModification.ModificationType.SUBTREE_MODIFIED);
+ Collection<DataTreeModification<Meter>> collection = new ArrayList<>();
+ collection.add(testData);
+ notifSupplierImpl.onDataTreeChanged(collection);
verify(notifProviderService, times(1)).publish(Matchers.any(MeterUpdated.class));
}
@Test
public void testDeleteChangeEvent() {
- final Set<InstanceIdentifier<?>> removeData = new HashSet<>();
- removeData.add(createTestMeterPath());
- notifSupplierImpl.onDataChanged(TestChangeEventBuildHelper.createTestDataEvent(null, null, removeData));
+ final TestData testData = new TestData(createTestMeterPath(),createTestMeter(),null,
+ DataObjectModification.ModificationType.DELETE);
+ Collection<DataTreeModification<Meter>> collection = new ArrayList<>();
+ collection.add(testData);
+ notifSupplierImpl.onDataTreeChanged(collection);
verify(notifProviderService, times(1)).publish(Matchers.any(MeterRemoved.class));
}
builder.setMeterId(new MeterId(METER_ID));
return builder.build();
}
+
+ private static Meter createUpdatedTestMeter(){
+ final MeterBuilder builder = new MeterBuilder();
+ builder.setMeterId(new MeterId(UPDATED_METER_ID));
+ return builder.build();
+ }
}
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
+import java.util.ArrayList;
+import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Matchers;
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import org.opendaylight.controller.md.sal.binding.api.DataObjectModification;
+import org.opendaylight.controller.md.sal.binding.api.DataTreeModification;
import org.opendaylight.controller.sal.binding.api.NotificationProviderService;
import org.opendaylight.openflowplugin.applications.notification.supplier.impl.helper.TestChangeEventBuildHelper;
+import org.opendaylight.openflowplugin.applications.notification.supplier.impl.helper.TestData;
import org.opendaylight.openflowplugin.applications.notification.supplier.impl.helper.TestSupplierVerifyHelper;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowId;
public class FlowStatNotificationSupplierImplTest {
- private static final String FLOW_NODE_ID = "test-111";
+ private static final String FLOW_NODE_ID = "openflow:111";
private static final Short FLOW_TABLE_ID = 111;
private static final String FLOW_ID = "test-flow-111";
private FlowStatNotificationSupplierImpl notifSupplierImpl;
TestSupplierVerifyHelper.verifyDataChangeRegistration(dataBroker);
}
- @Test(expected = IllegalArgumentException.class)
+ @Test(expected = NullPointerException.class)
public void testNullChangeEvent() {
- notifSupplierImpl.onDataChanged(null);
+ notifSupplierImpl.onDataTreeChanged(null);
}
- @Test
+ @Test(expected = NullPointerException.class)
public void testNullableChangeEvent() {
- notifSupplierImpl.onDataChanged(TestChangeEventBuildHelper.createEmptyTestDataEvent());
+ notifSupplierImpl.onDataTreeChanged( TestChangeEventBuildHelper.createNullTestDataTreeEvent());
}
@Test
public void testEmptyChangeEvent() {
- notifSupplierImpl.onDataChanged(TestChangeEventBuildHelper.createEmptyTestDataEvent());
+ notifSupplierImpl.onDataTreeChanged(TestChangeEventBuildHelper.createEmptyTestDataTreeEvent());
}
@Test
@Test
public void testCreateChangeEvent() {
- final Map<InstanceIdentifier<?>, DataObject> createdData = new HashMap<>();
- createdData.put(createTestFlowStatPath(), createTestFlowStat());
- notifSupplierImpl.onDataChanged(TestChangeEventBuildHelper.createTestDataEvent(createdData, null, null));
+ final TestData testData = new TestData(createTestFlowStatPath(),null,createTestFlowStat(),
+ DataObjectModification.ModificationType.WRITE);
+ Collection<DataTreeModification<FlowStatistics>> collection = new ArrayList<>();
+ collection.add(testData);
+ notifSupplierImpl.onDataTreeChanged(collection);
verify(notifProviderService, times(1)).publish(Matchers.any(FlowsStatisticsUpdate.class));
}
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
+import java.util.ArrayList;
+import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Matchers;
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import org.opendaylight.controller.md.sal.binding.api.DataObjectModification;
+import org.opendaylight.controller.md.sal.binding.api.DataTreeModification;
import org.opendaylight.controller.sal.binding.api.NotificationProviderService;
import org.opendaylight.openflowplugin.applications.notification.supplier.impl.helper.TestChangeEventBuildHelper;
+import org.opendaylight.openflowplugin.applications.notification.supplier.impl.helper.TestData;
import org.opendaylight.openflowplugin.applications.notification.supplier.impl.helper.TestSupplierVerifyHelper;
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.inventory.rev130819.tables.TableKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.FlowTableStatisticsData;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.FlowTableStatisticsUpdate;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.flow.table.statistics.FlowTableStatistics;
public class FlowTableStatNotificationSupplierImplTest {
- private static final String FLOW_NODE_ID = "test-111";
+ private static final String FLOW_NODE_ID = "openflow:111";
private static final Short FLOW_TABLE_ID = 111;
private static final String FLOW_ID = "test-flow-111";
private FlowTableStatNotificationSupplierImpl notifSupplierImpl;
TestSupplierVerifyHelper.verifyDataChangeRegistration(dataBroker);
}
- @Test(expected = IllegalArgumentException.class)
+ @Test(expected = NullPointerException.class)
public void testNullChangeEvent() {
- notifSupplierImpl.onDataChanged(null);
+ notifSupplierImpl.onDataTreeChanged(null);
}
- @Test
+ @Test(expected = NullPointerException.class)
public void testNullableChangeEvent() {
- notifSupplierImpl.onDataChanged(TestChangeEventBuildHelper.createEmptyTestDataEvent());
+ notifSupplierImpl.onDataTreeChanged( TestChangeEventBuildHelper.createNullTestDataTreeEvent());
}
@Test
public void testEmptyChangeEvent() {
- notifSupplierImpl.onDataChanged(TestChangeEventBuildHelper.createEmptyTestDataEvent());
+ notifSupplierImpl.onDataTreeChanged( TestChangeEventBuildHelper.createEmptyTestDataTreeEvent());
}
@Test
@Test
public void testCreateChangeEvent() {
- final Map<InstanceIdentifier<?>, DataObject> createdData = new HashMap<>();
- createdData.put(createTestFlowTableStatPath(), createTestFlowTableStat());
- notifSupplierImpl.onDataChanged(TestChangeEventBuildHelper.createTestDataEvent(createdData, null, null));
+ final TestData testData = new TestData(createTestFlowTableStatPath(),null,createTestFlowTableStat(),
+ DataObjectModification.ModificationType.WRITE);
+ Collection<DataTreeModification<FlowTableStatistics>> collection = new ArrayList<>();
+ collection.add(testData);
+ notifSupplierImpl.onDataTreeChanged(collection);
verify(notifProviderService, times(1)).publish(Matchers.any(FlowTableStatisticsUpdate.class));
}
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
+import java.util.ArrayList;
+import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Matchers;
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import org.opendaylight.controller.md.sal.binding.api.DataObjectModification;
+import org.opendaylight.controller.md.sal.binding.api.DataTreeModification;
import org.opendaylight.controller.sal.binding.api.NotificationProviderService;
import org.opendaylight.openflowplugin.applications.notification.supplier.impl.helper.TestChangeEventBuildHelper;
+import org.opendaylight.openflowplugin.applications.notification.supplier.impl.helper.TestData;
import org.opendaylight.openflowplugin.applications.notification.supplier.impl.helper.TestSupplierVerifyHelper;
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.Flow;
import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GroupStatisticsUpdated;
import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.NodeGroupStatistics;
import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.group.statistics.GroupStatistics;
public class GroupStatNotificationSupplierImplTest {
- private static final String FLOW_NODE_ID = "test-111";
+ private static final String FLOW_NODE_ID = "openflow:111";
private static final Long FLOW_TABLE_ID = 111L;
private GroupStatNotificationSupplierImpl notifSupplierImpl;
private NotificationProviderService notifProviderService;
TestSupplierVerifyHelper.verifyDataChangeRegistration(dataBroker);
}
- @Test(expected = IllegalArgumentException.class)
+ @Test(expected = NullPointerException.class)
public void testNullChangeEvent() {
- notifSupplierImpl.onDataChanged(null);
+ notifSupplierImpl.onDataTreeChanged(null);
}
- @Test
+ @Test(expected = NullPointerException.class)
public void testNullableChangeEvent() {
- notifSupplierImpl.onDataChanged(TestChangeEventBuildHelper.createEmptyTestDataEvent());
+ notifSupplierImpl.onDataTreeChanged(TestChangeEventBuildHelper.createNullTestDataTreeEvent());
}
@Test
public void testEmptyChangeEvent() {
- notifSupplierImpl.onDataChanged(TestChangeEventBuildHelper.createEmptyTestDataEvent());
+ notifSupplierImpl.onDataTreeChanged( TestChangeEventBuildHelper.createEmptyTestDataTreeEvent());
}
@Test
@Test
public void testCreateChangeEvent() {
- final Map<InstanceIdentifier<?>, DataObject> createdData = new HashMap<>();
- createdData.put(createTestGroupStatPath(), createTestGroupStat());
- notifSupplierImpl.onDataChanged(TestChangeEventBuildHelper.createTestDataEvent(createdData, null, null));
+ final TestData testData = new TestData(createTestGroupStatPath(),null,createTestGroupStat(),
+ DataObjectModification.ModificationType.WRITE);
+ Collection<DataTreeModification<GroupStatistics>> collection = new ArrayList<>();
+ collection.add(testData);
+ notifSupplierImpl.onDataTreeChanged(collection);
verify(notifProviderService, times(1)).publish(Matchers.any(GroupStatisticsUpdated.class));
}
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
+import java.util.ArrayList;
+import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Matchers;
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import org.opendaylight.controller.md.sal.binding.api.DataObjectModification;
+import org.opendaylight.controller.md.sal.binding.api.DataTreeModification;
import org.opendaylight.controller.sal.binding.api.NotificationProviderService;
import org.opendaylight.openflowplugin.applications.notification.supplier.impl.helper.TestChangeEventBuildHelper;
+import org.opendaylight.openflowplugin.applications.notification.supplier.impl.helper.TestData;
import org.opendaylight.openflowplugin.applications.notification.supplier.impl.helper.TestSupplierVerifyHelper;
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;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.meters.MeterKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow;
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;
public class MeterStatNotificationSupplierImplTest {
- private static final String FLOW_NODE_ID = "test-111";
+ private static final String FLOW_NODE_ID = "openflow:111";
private static final Long FLOW_METER_ID = 111L;
private MeterStatNotificationSupplierImpl notifSupplierImpl;
private NotificationProviderService notifProviderService;
TestSupplierVerifyHelper.verifyDataChangeRegistration(dataBroker);
}
- @Test(expected = IllegalArgumentException.class)
+ @Test(expected = NullPointerException.class)
public void testNullChangeEvent() {
- notifSupplierImpl.onDataChanged(null);
+ notifSupplierImpl.onDataTreeChanged(null);
}
- @Test
+ @Test(expected = NullPointerException.class)
public void testNullableChangeEvent() {
- notifSupplierImpl.onDataChanged(TestChangeEventBuildHelper.createEmptyTestDataEvent());
+ notifSupplierImpl.onDataTreeChanged(TestChangeEventBuildHelper.createNullTestDataTreeEvent());
}
@Test
public void testEmptyChangeEvent() {
- notifSupplierImpl.onDataChanged(TestChangeEventBuildHelper.createEmptyTestDataEvent());
+ notifSupplierImpl.onDataTreeChanged(TestChangeEventBuildHelper.createEmptyTestDataTreeEvent());
}
@Test
@Test
public void testCreateChangeEvent() {
- final Map<InstanceIdentifier<?>, DataObject> createdData = new HashMap<>();
- createdData.put(createTestMeterStatPath(), createTestMeterStat());
- notifSupplierImpl.onDataChanged(TestChangeEventBuildHelper.createTestDataEvent(createdData, null, null));
+ final TestData testData = new TestData(createTestMeterStatPath(),null,createTestMeterStat(),
+ DataObjectModification.ModificationType.WRITE);
+ Collection<DataTreeModification<MeterStatistics>> collection = new ArrayList<>();
+ collection.add(testData);
+ notifSupplierImpl.onDataTreeChanged(collection);
verify(notifProviderService, times(1)).publish(Matchers.any(MeterStatisticsUpdated.class));
}
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
+import java.util.ArrayList;
+import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Matchers;
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import org.opendaylight.controller.md.sal.binding.api.DataObjectModification;
+import org.opendaylight.controller.md.sal.binding.api.DataTreeModification;
import org.opendaylight.controller.sal.binding.api.NotificationProviderService;
import org.opendaylight.openflowplugin.applications.notification.supplier.impl.helper.TestChangeEventBuildHelper;
+import org.opendaylight.openflowplugin.applications.notification.supplier.impl.helper.TestData;
import org.opendaylight.openflowplugin.applications.notification.supplier.impl.helper.TestSupplierVerifyHelper;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow;
import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorId;
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.node.NodeConnectorKey;
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.model.statistics.types.rev130925.NodeConnectorStatistics;
import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.FlowCapableNodeConnectorStatisticsData;
import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.NodeConnectorStatisticsUpdate;
import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.flow.capable.node.connector.statistics.FlowCapableNodeConnectorStatistics;
public class NodeConnectorStatNotificationSupplierImplTest {
- private static final String FLOW_NODE_ID = "test-111";
+ private static final String FLOW_NODE_ID = "openflow:111";
private static final String FLOW_CODE_CONNECTOR_ID = "test-con-111";
private NodeConnectorStatNotificationSupplierImpl notifSupplierImpl;
private NotificationProviderService notifProviderService;
TestSupplierVerifyHelper.verifyDataChangeRegistration(dataBroker);
}
- @Test(expected = IllegalArgumentException.class)
+ @Test(expected = NullPointerException.class)
public void testNullChangeEvent() {
- notifSupplierImpl.onDataChanged(null);
+ notifSupplierImpl.onDataTreeChanged(null);
}
- @Test
+ @Test(expected = NullPointerException.class)
public void testNullableChangeEvent() {
- notifSupplierImpl.onDataChanged(TestChangeEventBuildHelper.createEmptyTestDataEvent());
+ notifSupplierImpl.onDataTreeChanged(TestChangeEventBuildHelper.createNullTestDataTreeEvent());
}
@Test
public void testEmptyChangeEvent() {
- notifSupplierImpl.onDataChanged(TestChangeEventBuildHelper.createEmptyTestDataEvent());
+ notifSupplierImpl.onDataTreeChanged(TestChangeEventBuildHelper.createEmptyTestDataTreeEvent());
}
@Test
@Test
public void testCreateChangeEvent() {
- final Map<InstanceIdentifier<?>, DataObject> createdData = new HashMap<>();
- createdData.put(createTestConnectorStatPath(), createTestConnectorStat());
- notifSupplierImpl.onDataChanged(TestChangeEventBuildHelper.createTestDataEvent(createdData, null, null));
+ final TestData testData = new TestData(createTestConnectorStatPath(),null,createTestConnectorStat(),
+ DataObjectModification.ModificationType.WRITE);
+ Collection<DataTreeModification<FlowCapableNodeConnectorStatistics>> collection = new ArrayList<>();
+ collection.add(testData);
+ notifSupplierImpl.onDataTreeChanged(collection);
verify(notifProviderService, times(1)).publish(Matchers.any(NodeConnectorStatisticsUpdate.class));
}
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
+import java.util.ArrayList;
+import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Matchers;
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import org.opendaylight.controller.md.sal.binding.api.DataObjectModification;
+import org.opendaylight.controller.md.sal.binding.api.DataTreeModification;
import org.opendaylight.controller.sal.binding.api.NotificationProviderService;
import org.opendaylight.openflowplugin.applications.notification.supplier.impl.helper.TestChangeEventBuildHelper;
+import org.opendaylight.openflowplugin.applications.notification.supplier.impl.helper.TestData;
import org.opendaylight.openflowplugin.applications.notification.supplier.impl.helper.TestSupplierVerifyHelper;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNodeConnector;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.queues.Queue;
import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorId;
import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.FlowCapableNodeConnectorQueueStatisticsData;
import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.FlowCapableNodeConnectorQueueStatisticsDataBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.QueueStatisticsUpdate;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.flow.capable.node.connector.queue.statistics.FlowCapableNodeConnectorQueueStatistics;
import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.flow.capable.node.connector.queue.statistics.FlowCapableNodeConnectorQueueStatisticsBuilder;
import org.opendaylight.yangtools.yang.binding.DataObject;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
*/
public class QueueStatNotificationSupplierImplTest {
- private static final String FLOW_NODE_ID = "test-111";
+ private static final String FLOW_NODE_ID = "openflow:111";
private static final String FLOW_CODE_CONNECTOR_ID = "test-con-111";
private QueueStatNotificationSupplierImpl notifSupplierImpl;
private NotificationProviderService notifProviderService;
TestSupplierVerifyHelper.verifyDataChangeRegistration(dataBroker);
}
- @Test(expected = IllegalArgumentException.class)
+ @Test(expected = NullPointerException.class)
public void testNullChangeEvent() {
- notifSupplierImpl.onDataChanged(null);
+ notifSupplierImpl.onDataTreeChanged(null);
}
- @Test
+ @Test(expected = NullPointerException.class)
public void testNullableChangeEvent() {
- notifSupplierImpl.onDataChanged(TestChangeEventBuildHelper.createEmptyTestDataEvent());
+ notifSupplierImpl.onDataTreeChanged(TestChangeEventBuildHelper.createNullTestDataTreeEvent());
}
@Test
public void testEmptyChangeEvent() {
- notifSupplierImpl.onDataChanged(TestChangeEventBuildHelper.createEmptyTestDataEvent());
+ notifSupplierImpl.onDataTreeChanged(TestChangeEventBuildHelper.createEmptyTestDataTreeEvent());
}
@Test
@Test
public void testCreateChangeEvent() {
- final Map<InstanceIdentifier<?>, DataObject> createdData = new HashMap<>();
- createdData.put(createTestQueueStatPath(), createTestQueueStat());
- notifSupplierImpl.onDataChanged(TestChangeEventBuildHelper.createTestDataEvent(createdData, null, null));
+ final TestData testData = new TestData(createTestQueueStatPath(),null,createTestQueueStat(),
+ DataObjectModification.ModificationType.WRITE);
+ Collection<DataTreeModification<FlowCapableNodeConnectorQueueStatisticsData>> collection = new ArrayList<>();
+ collection.add(testData);
+ notifSupplierImpl.onDataTreeChanged(collection);
verify(notifProviderService, times(1)).publish(Matchers.any(QueueStatisticsUpdate.class));
}
--- /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.extension.vendor.nicira;
+
+import org.junit.After;
+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.extension.api.ConvertorActionToOFJava;
+import org.opendaylight.openflowplugin.extension.api.ExtensionConverterRegistrator;
+import org.opendaylight.openflowplugin.extension.api.TypeVersionKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action;
+
+/**
+ * Test for {@link NiciraExtensionProvider}.
+ */
+@RunWith(MockitoJUnitRunner.class)
+public class NiciraExtensionProviderTest {
+
+ @Mock
+ private ExtensionConverterRegistrator extensionConverterRegistrator;
+
+ private NiciraExtensionProvider niciraExtensionProvider;
+
+ @Before
+ public void setUp() throws Exception {
+
+ niciraExtensionProvider = new NiciraExtensionProvider();
+ niciraExtensionProvider.setExtensionConverterRegistrator(extensionConverterRegistrator);
+ }
+
+ @Test
+ public void testRegisterConverters() throws Exception {
+ niciraExtensionProvider.registerConverters();
+ Mockito.verify(extensionConverterRegistrator, Mockito.atLeastOnce()).registerActionConvertor(Matchers.<TypeVersionKey<? extends Action>>any(), Matchers.<ConvertorActionToOFJava<Action, org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.Action>>any());
+ }
+}
\ No newline at end of file
--- /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.extension.vendor.nicira.convertor.match;
+
+import static org.mockito.Mockito.when;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Matchers;
+import org.mockito.Mock;
+import org.mockito.runners.MockitoJUnitRunner;
+import org.opendaylight.openflowplugin.extension.api.ExtensionAugment;
+import org.opendaylight.openflowplugin.extension.api.path.MatchPath;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntry;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.ofj.nxm.nx.match.nshc._4.grouping.Nshc4ValuesBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.oxm.container.match.entry.value.Nshc4CaseValue;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.oxm.container.match.entry.value.Nshc4CaseValueBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.general.rev140714.general.extension.grouping.Extension;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchNotifPacketIn;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchNotifSwitchFlowRemoved;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchNotifUpdateFlowStats;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchNotifUpdateFlowStatsBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxmNxNshc4Key;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.nxm.nx.nshc._4.grouping.NxmNxNshc4Builder;
+import org.opendaylight.yangtools.yang.binding.Augmentation;
+
+/**
+ * Test for {@link Nshc4Convertor}.
+ */
+@RunWith(MockitoJUnitRunner.class)
+public class Nshc4ConvertorTest {
+ @Mock
+ private Extension extension;
+ @Mock
+ private MatchEntry matchEntry;
+
+ private Nshc4Convertor nshc4Convertor;
+
+ @Before
+ public void setUp() throws Exception {
+ final NxmNxNshc4Builder nxmNxNshc4Builder = new NxmNxNshc4Builder()
+ .setValue(1L);
+ final NxAugMatchNotifUpdateFlowStatsBuilder nxAugMatchNotifUpdateFlowStatsBuilder = new NxAugMatchNotifUpdateFlowStatsBuilder();
+ nxAugMatchNotifUpdateFlowStatsBuilder.setNxmNxNshc4(nxmNxNshc4Builder.build());
+
+ final Augmentation<Extension> extensionAugmentation = nxAugMatchNotifUpdateFlowStatsBuilder.build();
+ when(extension.getAugmentation(Matchers.<Class<Augmentation<Extension>>>any())).thenReturn(extensionAugmentation);
+
+ nshc4Convertor = new Nshc4Convertor();
+ }
+
+ @Test
+ public void testConvert() throws Exception {
+ final MatchEntry matchEntry = nshc4Convertor.convert(extension);
+ Assert.assertEquals(1, ((Nshc4CaseValue)matchEntry.getMatchEntryValue()).getNshc4Values().getNshc().intValue());
+ }
+
+ @Test
+ public void testConvert1() throws Exception {
+ final Nshc4ValuesBuilder nshc4ValuesBuilder = new Nshc4ValuesBuilder()
+ .setNshc(Long.valueOf(1));
+ final Nshc4CaseValueBuilder nshc4CaseValueBuilder = new Nshc4CaseValueBuilder()
+ .setNshc4Values(nshc4ValuesBuilder.build());
+
+ final Nshc4CaseValue nshc4CaseValue = nshc4CaseValueBuilder.build();
+
+ when(matchEntry.getMatchEntryValue()).thenReturn(nshc4CaseValue);
+
+ final ExtensionAugment<? extends Augmentation<Extension>> extensionAugment = nshc4Convertor.convert(matchEntry, MatchPath.PACKETRECEIVED_MATCH);
+ Assert.assertEquals(1, ((NxAugMatchNotifPacketIn)extensionAugment.getAugmentationObject()).getNxmNxNshc4().getValue().intValue());
+ Assert.assertEquals(extensionAugment.getKey(), NxmNxNshc4Key.class);
+
+ final ExtensionAugment<? extends Augmentation<Extension>> extensionAugment1 = nshc4Convertor.convert(matchEntry, MatchPath.SWITCHFLOWREMOVED_MATCH);
+ Assert.assertEquals(1, ((NxAugMatchNotifSwitchFlowRemoved)extensionAugment1.getAugmentationObject()).getNxmNxNshc4().getValue().intValue());
+ Assert.assertEquals(extensionAugment.getKey(), NxmNxNshc4Key.class);
+
+ final ExtensionAugment<? extends Augmentation<Extension>> extensionAugment2 = nshc4Convertor.convert(matchEntry, MatchPath.FLOWSSTATISTICSUPDATE_FLOWANDSTATISTICSMAPLIST_MATCH);
+ Assert.assertEquals(1, ((NxAugMatchNotifUpdateFlowStats)extensionAugment2.getAugmentationObject()).getNxmNxNshc4().getValue().intValue());
+ Assert.assertEquals(extensionAugment.getKey(), NxmNxNshc4Key.class);
+ }
+}
\ No newline at end of file
--- /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.extension.vendor.nicira.convertor.match;
+
+import static org.mockito.Mockito.when;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Matchers;
+import org.mockito.Mock;
+import org.mockito.runners.MockitoJUnitRunner;
+import org.opendaylight.openflowplugin.extension.api.ExtensionAugment;
+import org.opendaylight.openflowplugin.extension.api.path.MatchPath;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntry;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.ofj.nxm.nx.match.nsi.grouping.NsiValuesBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.oxm.container.match.entry.value.NsiCaseValue;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.oxm.container.match.entry.value.NsiCaseValueBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.general.rev140714.general.extension.grouping.Extension;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchNotifPacketIn;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchNotifSwitchFlowRemoved;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchNotifUpdateFlowStats;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchNotifUpdateFlowStatsBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxmNxNsiKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.nxm.nx.nsi.grouping.NxmNxNsiBuilder;
+import org.opendaylight.yangtools.yang.binding.Augmentation;
+
+/**
+ * Test for {@link NsiConvertor}.
+ */
+@RunWith(MockitoJUnitRunner.class)
+public class NsiConvertorTest {
+ @Mock
+ private Extension extension;
+ @Mock
+ private MatchEntry matchEntry;
+
+ private NsiConvertor nsiConvertor;
+
+ @Before
+ public void setUp() throws Exception {
+ final NxmNxNsiBuilder nxmNxNsiBuilder = new NxmNxNsiBuilder()
+ .setNsi((short)1);
+ final NxAugMatchNotifUpdateFlowStatsBuilder nxAugMatchNotifUpdateFlowStatsBuilder = new NxAugMatchNotifUpdateFlowStatsBuilder();
+ nxAugMatchNotifUpdateFlowStatsBuilder.setNxmNxNsi(nxmNxNsiBuilder.build());
+
+ final Augmentation<Extension> extensionAugmentation = nxAugMatchNotifUpdateFlowStatsBuilder.build();
+ when(extension.getAugmentation(Matchers.<Class<Augmentation<Extension>>>any())).thenReturn(extensionAugmentation);
+
+ nsiConvertor = new NsiConvertor();
+ }
+
+ @Test
+ public void testConvert() throws Exception {
+ final MatchEntry matchEntry = nsiConvertor.convert(extension);
+ Assert.assertEquals(1, ((NsiCaseValue)matchEntry.getMatchEntryValue()).getNsiValues().getNsi().intValue());
+ }
+
+ @Test
+ public void testConvert1() throws Exception {
+ final NsiValuesBuilder nsiValuesBuilder = new NsiValuesBuilder()
+ .setNsi(Short.valueOf((short)1));
+ final NsiCaseValueBuilder nsiCaseValueBuilder = new NsiCaseValueBuilder()
+ .setNsiValues(nsiValuesBuilder.build());
+
+ final NsiCaseValue nsiCaseValue = nsiCaseValueBuilder.build();
+
+ when(matchEntry.getMatchEntryValue()).thenReturn(nsiCaseValue);
+
+ final ExtensionAugment<? extends Augmentation<Extension>> extensionAugment = nsiConvertor.convert(matchEntry, MatchPath.PACKETRECEIVED_MATCH);
+ Assert.assertEquals(1, ((NxAugMatchNotifPacketIn)extensionAugment.getAugmentationObject()).getNxmNxNsi().getNsi().intValue());
+ Assert.assertEquals(extensionAugment.getKey(), NxmNxNsiKey.class);
+
+ final ExtensionAugment<? extends Augmentation<Extension>> extensionAugment1 = nsiConvertor.convert(matchEntry, MatchPath.SWITCHFLOWREMOVED_MATCH);
+ Assert.assertEquals(1, ((NxAugMatchNotifSwitchFlowRemoved)extensionAugment1.getAugmentationObject()).getNxmNxNsi().getNsi().intValue());
+ Assert.assertEquals(extensionAugment.getKey(), NxmNxNsiKey.class);
+
+ final ExtensionAugment<? extends Augmentation<Extension>> extensionAugment2 = nsiConvertor.convert(matchEntry, MatchPath.FLOWSSTATISTICSUPDATE_FLOWANDSTATISTICSMAPLIST_MATCH);
+ Assert.assertEquals(1, ((NxAugMatchNotifUpdateFlowStats)extensionAugment2.getAugmentationObject()).getNxmNxNsi().getNsi().intValue());
+ Assert.assertEquals(extensionAugment.getKey(), NxmNxNsiKey.class);
+ }
+
+}
\ No newline at end of file
--- /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.extension.vendor.nicira.convertor.match;
+
+import static org.mockito.Mockito.when;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Matchers;
+import org.mockito.Mock;
+import org.mockito.runners.MockitoJUnitRunner;
+import org.opendaylight.openflowplugin.extension.api.ExtensionAugment;
+import org.opendaylight.openflowplugin.extension.api.path.MatchPath;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntry;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.ofj.nxm.nx.match.nsp.grouping.NspValuesBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.oxm.container.match.entry.value.NspCaseValue;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.oxm.container.match.entry.value.NspCaseValueBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.general.rev140714.general.extension.grouping.Extension;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchNotifPacketIn;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchNotifSwitchFlowRemoved;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchNotifUpdateFlowStats;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchNotifUpdateFlowStatsBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxmNxNspKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.nxm.nx.nsp.grouping.NxmNxNspBuilder;
+import org.opendaylight.yangtools.yang.binding.Augmentation;
+
+/**
+ * Test for {@link NspConvertor}.
+ */
+@RunWith(MockitoJUnitRunner.class)
+public class NspConvertorTest {
+ @Mock
+ private Extension extension;
+ @Mock
+ private MatchEntry matchEntry;
+
+ private NspConvertor nspConvertor;
+
+ @Before
+ public void setUp() throws Exception {
+ final NxmNxNspBuilder nxmNxNspBuilder = new NxmNxNspBuilder()
+ .setValue(Long.valueOf(1L));
+ final NxAugMatchNotifUpdateFlowStatsBuilder nxAugMatchNotifUpdateFlowStatsBuilder = new NxAugMatchNotifUpdateFlowStatsBuilder();
+ nxAugMatchNotifUpdateFlowStatsBuilder.setNxmNxNsp(nxmNxNspBuilder.build());
+
+ final Augmentation<Extension> extensionAugmentation = nxAugMatchNotifUpdateFlowStatsBuilder.build();
+ when(extension.getAugmentation(Matchers.<Class<Augmentation<Extension>>>any())).thenReturn(extensionAugmentation);
+
+ nspConvertor = new NspConvertor();
+ }
+
+ @Test
+ public void testConvert() throws Exception {
+ final MatchEntry matchEntry = nspConvertor.convert(extension);
+ Assert.assertEquals(1, ((NspCaseValue)matchEntry.getMatchEntryValue()).getNspValues().getNsp().intValue());
+ }
+
+ @Test
+ public void testConvert1() throws Exception {
+ final NspValuesBuilder nspValuesBuilder = new NspValuesBuilder()
+ .setNsp(Long.valueOf(2L));
+ final NspCaseValueBuilder nspCaseValueBuilder = new NspCaseValueBuilder()
+ .setNspValues(nspValuesBuilder.build());
+
+ final NspCaseValue nspCaseValue = nspCaseValueBuilder.build();
+
+ when(matchEntry.getMatchEntryValue()).thenReturn(nspCaseValue);
+
+ final ExtensionAugment<? extends Augmentation<Extension>> extensionAugment = nspConvertor.convert(matchEntry, MatchPath.PACKETRECEIVED_MATCH);
+ Assert.assertEquals(2, ((NxAugMatchNotifPacketIn)extensionAugment.getAugmentationObject()).getNxmNxNsp().getValue().longValue());
+ Assert.assertEquals(extensionAugment.getKey(), NxmNxNspKey.class);
+
+ final ExtensionAugment<? extends Augmentation<Extension>> extensionAugment1 = nspConvertor.convert(matchEntry, MatchPath.SWITCHFLOWREMOVED_MATCH);
+ Assert.assertEquals(2, ((NxAugMatchNotifSwitchFlowRemoved)extensionAugment1.getAugmentationObject()).getNxmNxNsp().getValue().longValue());
+ Assert.assertEquals(extensionAugment.getKey(), NxmNxNspKey.class);
+
+ final ExtensionAugment<? extends Augmentation<Extension>> extensionAugment2 = nspConvertor.convert(matchEntry, MatchPath.FLOWSSTATISTICSUPDATE_FLOWANDSTATISTICSMAPLIST_MATCH);
+ Assert.assertEquals(2, ((NxAugMatchNotifUpdateFlowStats)extensionAugment2.getAugmentationObject()).getNxmNxNsp().getValue().longValue());
+ Assert.assertEquals(extensionAugment.getKey(), NxmNxNspKey.class);
+ }
+}
\ No newline at end of file
--- /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.extension.vendor.nicira.convertor.match;
+
+import static org.mockito.Mockito.when;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Matchers;
+import org.mockito.Mock;
+import org.mockito.runners.MockitoJUnitRunner;
+import org.opendaylight.openflowplugin.extension.api.ExtensionAugment;
+import org.opendaylight.openflowplugin.extension.api.path.MatchPath;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.PortNumber;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntry;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.ofj.nxm.of.match.tcp.dst.grouping.TcpDstValuesBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.oxm.container.match.entry.value.TcpDstCaseValue;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.oxm.container.match.entry.value.TcpDstCaseValueBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.general.rev140714.general.extension.grouping.Extension;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchNotifPacketIn;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchNotifSwitchFlowRemoved;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchNotifUpdateFlowStats;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchNotifUpdateFlowStatsBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxmOfTcpDstKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.nxm.of.tcp.dst.grouping.NxmOfTcpDstBuilder;
+import org.opendaylight.yangtools.yang.binding.Augmentation;
+
+/**
+ * Test for {@link TcpDstConvertor}.
+ */
+@RunWith(MockitoJUnitRunner.class)
+public class TcpDstConvertorTest {
+ @Mock
+ private Extension extension;
+ @Mock
+ private MatchEntry matchEntry;
+
+ private static final PortNumber DEFAULT_PORT = new PortNumber(9999);
+
+ private TcpDstConvertor tcpDstConvertor;
+
+ @Before
+ public void setUp() throws Exception {
+ final NxmOfTcpDstBuilder nxmOfTcpDstBuilder = new NxmOfTcpDstBuilder()
+ .setMask(1)
+ .setPort(DEFAULT_PORT);
+ final NxAugMatchNotifUpdateFlowStatsBuilder nxAugMatchNotifUpdateFlowStatsBuilder = new NxAugMatchNotifUpdateFlowStatsBuilder();
+ nxAugMatchNotifUpdateFlowStatsBuilder.setNxmOfTcpDst(nxmOfTcpDstBuilder.build());
+
+ final Augmentation<Extension> extensionAugmentation = nxAugMatchNotifUpdateFlowStatsBuilder.build();
+ when(extension.getAugmentation(Matchers.<Class<Augmentation<Extension>>>any())).thenReturn(extensionAugmentation);
+
+ tcpDstConvertor = new TcpDstConvertor();
+ }
+
+ @Test
+ public void testConvert() throws Exception {
+ final MatchEntry matchEntry = tcpDstConvertor.convert(extension);
+ Assert.assertEquals(1, ((TcpDstCaseValue)matchEntry.getMatchEntryValue()).getTcpDstValues().getMask().intValue());
+ Assert.assertEquals(DEFAULT_PORT, ((TcpDstCaseValue)matchEntry.getMatchEntryValue()).getTcpDstValues().getPort());
+ }
+
+ @Test
+ public void testConvert1() throws Exception {
+ final TcpDstValuesBuilder tcpDstValuesBuilder = new TcpDstValuesBuilder()
+ .setMask(2)
+ .setPort(DEFAULT_PORT);
+ final TcpDstCaseValueBuilder tcpDstCaseValueBuilder = new TcpDstCaseValueBuilder()
+ .setTcpDstValues(tcpDstValuesBuilder.build());
+
+ final TcpDstCaseValue tcpDstCaseValue = tcpDstCaseValueBuilder.build();
+
+ when(matchEntry.getMatchEntryValue()).thenReturn(tcpDstCaseValue);
+
+ final ExtensionAugment<? extends Augmentation<Extension>> extensionAugment = tcpDstConvertor.convert(matchEntry, MatchPath.PACKETRECEIVED_MATCH);
+ Assert.assertEquals(2, ((NxAugMatchNotifPacketIn)extensionAugment.getAugmentationObject()).getNxmOfTcpDst().getMask().intValue());
+ Assert.assertEquals(DEFAULT_PORT, ((NxAugMatchNotifPacketIn)extensionAugment.getAugmentationObject()).getNxmOfTcpDst().getPort());
+ Assert.assertEquals(extensionAugment.getKey(), NxmOfTcpDstKey.class);
+
+ final ExtensionAugment<? extends Augmentation<Extension>> extensionAugment1 = tcpDstConvertor.convert(matchEntry, MatchPath.SWITCHFLOWREMOVED_MATCH);
+ Assert.assertEquals(2, ((NxAugMatchNotifSwitchFlowRemoved)extensionAugment1.getAugmentationObject()).getNxmOfTcpDst().getMask().intValue());
+ Assert.assertEquals(DEFAULT_PORT, ((NxAugMatchNotifSwitchFlowRemoved)extensionAugment1.getAugmentationObject()).getNxmOfTcpDst().getPort());
+ Assert.assertEquals(extensionAugment.getKey(), NxmOfTcpDstKey.class);
+
+ final ExtensionAugment<? extends Augmentation<Extension>> extensionAugment2 = tcpDstConvertor.convert(matchEntry, MatchPath.FLOWSSTATISTICSUPDATE_FLOWANDSTATISTICSMAPLIST_MATCH);
+ Assert.assertEquals(2, ((NxAugMatchNotifUpdateFlowStats)extensionAugment2.getAugmentationObject()).getNxmOfTcpDst().getMask().intValue());
+ Assert.assertEquals(DEFAULT_PORT, ((NxAugMatchNotifUpdateFlowStats)extensionAugment2.getAugmentationObject()).getNxmOfTcpDst().getPort());
+ Assert.assertEquals(extensionAugment.getKey(), NxmOfTcpDstKey.class);
+ }
+}
\ No newline at end of file
--- /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.extension.vendor.nicira.convertor.match;
+
+import static org.mockito.Mockito.when;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Matchers;
+import org.mockito.Mock;
+import org.mockito.runners.MockitoJUnitRunner;
+import org.opendaylight.openflowplugin.extension.api.ExtensionAugment;
+import org.opendaylight.openflowplugin.extension.api.path.MatchPath;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.PortNumber;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntry;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.ofj.nxm.of.match.tcp.src.grouping.TcpSrcValuesBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.oxm.container.match.entry.value.TcpSrcCaseValue;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.oxm.container.match.entry.value.TcpSrcCaseValueBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.general.rev140714.general.extension.grouping.Extension;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchNotifPacketIn;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchNotifSwitchFlowRemoved;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchNotifUpdateFlowStats;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchNotifUpdateFlowStatsBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxmOfTcpSrcKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.nxm.of.tcp.src.grouping.NxmOfTcpSrcBuilder;
+import org.opendaylight.yangtools.yang.binding.Augmentation;
+
+/**
+ * Test for {@link TcpSrcConvertor}.
+ */
+@RunWith(MockitoJUnitRunner.class)
+public class TcpSrcConvertorTest {
+ @Mock
+ private Extension extension;
+ @Mock
+ private MatchEntry matchEntry;
+
+ private static final PortNumber DEFAULT_PORT = new PortNumber(9999);
+
+ private TcpSrcConvertor tcpSrcConvertor;
+
+ @Before
+ public void setUp() throws Exception {
+ final NxmOfTcpSrcBuilder nxmOfTcpSrcBuilder = new NxmOfTcpSrcBuilder()
+ .setMask(1)
+ .setPort(DEFAULT_PORT);
+ final NxAugMatchNotifUpdateFlowStatsBuilder nxAugMatchNotifUpdateFlowStatsBuilder = new NxAugMatchNotifUpdateFlowStatsBuilder();
+ nxAugMatchNotifUpdateFlowStatsBuilder.setNxmOfTcpSrc(nxmOfTcpSrcBuilder.build());
+
+ final Augmentation<Extension> extensionAugmentation = nxAugMatchNotifUpdateFlowStatsBuilder.build();
+ when(extension.getAugmentation(Matchers.<Class<Augmentation<Extension>>>any())).thenReturn(extensionAugmentation);
+
+ tcpSrcConvertor = new TcpSrcConvertor();
+ }
+
+ @Test
+ public void testConvert() throws Exception {
+ final MatchEntry matchEntry = tcpSrcConvertor.convert(extension);
+ Assert.assertEquals(1, ((TcpSrcCaseValue)matchEntry.getMatchEntryValue()).getTcpSrcValues().getMask().intValue());
+ Assert.assertEquals(DEFAULT_PORT, ((TcpSrcCaseValue)matchEntry.getMatchEntryValue()).getTcpSrcValues().getPort());
+ }
+
+ @Test
+ public void testConvert1() throws Exception {
+ final TcpSrcValuesBuilder tcpSrcValuesBuilder = new TcpSrcValuesBuilder()
+ .setMask(2)
+ .setPort(DEFAULT_PORT);
+ final TcpSrcCaseValueBuilder tcpSrcCaseValueBuilder = new TcpSrcCaseValueBuilder()
+ .setTcpSrcValues(tcpSrcValuesBuilder.build());
+
+ final TcpSrcCaseValue tcpSrcCaseValue = tcpSrcCaseValueBuilder.build();
+
+ when(matchEntry.getMatchEntryValue()).thenReturn(tcpSrcCaseValue);
+
+ final ExtensionAugment<? extends Augmentation<Extension>> extensionAugment = tcpSrcConvertor.convert(matchEntry, MatchPath.PACKETRECEIVED_MATCH);
+ Assert.assertEquals(2, ((NxAugMatchNotifPacketIn)extensionAugment.getAugmentationObject()).getNxmOfTcpSrc().getMask().intValue());
+ Assert.assertEquals(DEFAULT_PORT, ((NxAugMatchNotifPacketIn)extensionAugment.getAugmentationObject()).getNxmOfTcpSrc().getPort());
+ Assert.assertEquals(extensionAugment.getKey(), NxmOfTcpSrcKey.class);
+
+ final ExtensionAugment<? extends Augmentation<Extension>> extensionAugment1 = tcpSrcConvertor.convert(matchEntry, MatchPath.SWITCHFLOWREMOVED_MATCH);
+ Assert.assertEquals(2, ((NxAugMatchNotifSwitchFlowRemoved)extensionAugment1.getAugmentationObject()).getNxmOfTcpSrc().getMask().intValue());
+ Assert.assertEquals(DEFAULT_PORT, ((NxAugMatchNotifSwitchFlowRemoved)extensionAugment1.getAugmentationObject()).getNxmOfTcpSrc().getPort());
+ Assert.assertEquals(extensionAugment.getKey(), NxmOfTcpSrcKey.class);
+
+ final ExtensionAugment<? extends Augmentation<Extension>> extensionAugment2 = tcpSrcConvertor.convert(matchEntry, MatchPath.FLOWSSTATISTICSUPDATE_FLOWANDSTATISTICSMAPLIST_MATCH);
+ Assert.assertEquals(2, ((NxAugMatchNotifUpdateFlowStats)extensionAugment2.getAugmentationObject()).getNxmOfTcpSrc().getMask().intValue());
+ Assert.assertEquals(DEFAULT_PORT, ((NxAugMatchNotifUpdateFlowStats)extensionAugment2.getAugmentationObject()).getNxmOfTcpSrc().getPort());
+ Assert.assertEquals(extensionAugment.getKey(), NxmOfTcpSrcKey.class);
+ }
+}
\ No newline at end of file
--- /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.extension.vendor.nicira.convertor.match;
+
+import static org.mockito.Mockito.when;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Matchers;
+import org.mockito.Mock;
+import org.mockito.runners.MockitoJUnitRunner;
+import org.opendaylight.openflowplugin.extension.api.ExtensionAugment;
+import org.opendaylight.openflowplugin.extension.api.path.MatchPath;
+import org.opendaylight.openflowplugin.extension.vendor.nicira.convertor.IpConverter;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntry;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.ofj.nxm.nx.match.tun.ipv4.dst.grouping.TunIpv4DstValuesBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.oxm.container.match.entry.value.TunIpv4DstCaseValue;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.oxm.container.match.entry.value.TunIpv4DstCaseValueBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.general.rev140714.general.extension.grouping.Extension;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchNotifPacketIn;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchNotifSwitchFlowRemoved;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchNotifUpdateFlowStats;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchNotifUpdateFlowStatsBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxmNxTunIpv4DstKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.nxm.nx.tun.ipv4.dst.grouping.NxmNxTunIpv4DstBuilder;
+import org.opendaylight.yangtools.yang.binding.Augmentation;
+
+/**
+ * Test for {@link TunIPv4DstConvertor}.
+ */
+@RunWith(MockitoJUnitRunner.class)
+public class TunIPv4DstConvertorTest {
+ @Mock
+ private Extension extension;
+ @Mock
+ private MatchEntry matchEntry;
+
+ private static final Ipv4Address IPV4_ADDRESS = Ipv4Address.getDefaultInstance("1.2.3.4");
+
+ private TunIPv4DstConvertor tunIPv4DstConvertor;
+
+ @Before
+ public void setUp() throws Exception {
+ final NxmNxTunIpv4DstBuilder nxmNxTunIpv4DstBuilder = new NxmNxTunIpv4DstBuilder()
+ .setIpv4Address(IPV4_ADDRESS);
+ final NxAugMatchNotifUpdateFlowStatsBuilder nxAugMatchNotifUpdateFlowStatsBuilder = new NxAugMatchNotifUpdateFlowStatsBuilder();
+ nxAugMatchNotifUpdateFlowStatsBuilder.setNxmNxTunIpv4Dst(nxmNxTunIpv4DstBuilder.build());
+
+ final Augmentation<Extension> extensionAugmentation = nxAugMatchNotifUpdateFlowStatsBuilder.build();
+ when(extension.getAugmentation(Matchers.<Class<Augmentation<Extension>>>any())).thenReturn(extensionAugmentation);
+
+ tunIPv4DstConvertor = new TunIPv4DstConvertor();
+ }
+
+ @Test
+ public void testConvert() throws Exception {
+ final MatchEntry matchEntry = tunIPv4DstConvertor.convert(extension);
+ Assert.assertEquals(IpConverter.Ipv4AddressToLong(IPV4_ADDRESS), ((TunIpv4DstCaseValue)matchEntry.getMatchEntryValue()).getTunIpv4DstValues().getValue().longValue());
+ }
+
+ @Test
+ public void testConvert1() throws Exception {
+ final TunIpv4DstValuesBuilder tunIpv4DstValuesBuilder = new TunIpv4DstValuesBuilder()
+ .setValue(IpConverter.Ipv4AddressToLong(IPV4_ADDRESS));
+ final TunIpv4DstCaseValueBuilder tunIpv4DstCaseValueBuilder = new TunIpv4DstCaseValueBuilder()
+ .setTunIpv4DstValues(tunIpv4DstValuesBuilder.build());
+
+ final TunIpv4DstCaseValue tunIpv4DstCaseValue = tunIpv4DstCaseValueBuilder.build();
+
+ when(matchEntry.getMatchEntryValue()).thenReturn(tunIpv4DstCaseValue);
+
+ final ExtensionAugment<? extends Augmentation<Extension>> extensionAugment = tunIPv4DstConvertor.convert(matchEntry, MatchPath.PACKETRECEIVED_MATCH);
+ Assert.assertEquals(IPV4_ADDRESS, ((NxAugMatchNotifPacketIn)extensionAugment.getAugmentationObject()).getNxmNxTunIpv4Dst().getIpv4Address());
+ Assert.assertEquals(extensionAugment.getKey(), NxmNxTunIpv4DstKey.class);
+
+ final ExtensionAugment<? extends Augmentation<Extension>> extensionAugment1 = tunIPv4DstConvertor.convert(matchEntry, MatchPath.SWITCHFLOWREMOVED_MATCH);
+ Assert.assertEquals(IPV4_ADDRESS, ((NxAugMatchNotifSwitchFlowRemoved)extensionAugment1.getAugmentationObject()).getNxmNxTunIpv4Dst().getIpv4Address());
+ Assert.assertEquals(extensionAugment.getKey(), NxmNxTunIpv4DstKey.class);
+
+ final ExtensionAugment<? extends Augmentation<Extension>> extensionAugment2 = tunIPv4DstConvertor.convert(matchEntry, MatchPath.FLOWSSTATISTICSUPDATE_FLOWANDSTATISTICSMAPLIST_MATCH);
+ Assert.assertEquals(IPV4_ADDRESS, ((NxAugMatchNotifUpdateFlowStats)extensionAugment2.getAugmentationObject()).getNxmNxTunIpv4Dst().getIpv4Address());
+ Assert.assertEquals(extensionAugment.getKey(), NxmNxTunIpv4DstKey.class);
+ }
+
+}
\ No newline at end of file
--- /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.extension.vendor.nicira.convertor.match;
+
+import static org.mockito.Mockito.when;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Matchers;
+import org.mockito.Mock;
+import org.mockito.runners.MockitoJUnitRunner;
+import org.opendaylight.openflowplugin.extension.api.ExtensionAugment;
+import org.opendaylight.openflowplugin.extension.api.path.MatchPath;
+import org.opendaylight.openflowplugin.extension.vendor.nicira.convertor.IpConverter;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntry;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.ofj.nxm.nx.match.tun.ipv4.src.grouping.TunIpv4SrcValuesBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.oxm.container.match.entry.value.TunIpv4SrcCaseValue;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.oxm.container.match.entry.value.TunIpv4SrcCaseValueBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.general.rev140714.general.extension.grouping.Extension;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchNotifPacketIn;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchNotifSwitchFlowRemoved;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchNotifUpdateFlowStats;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchNotifUpdateFlowStatsBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxmNxTunIpv4SrcKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.nxm.nx.tun.ipv4.src.grouping.NxmNxTunIpv4SrcBuilder;
+import org.opendaylight.yangtools.yang.binding.Augmentation;
+
+/**
+ * Test for {@link TunIPv4SrcConvertor}.
+ */
+@RunWith(MockitoJUnitRunner.class)
+public class TunIPv4SrcConvertorTest {
+ @Mock
+ private Extension extension;
+ @Mock
+ private MatchEntry matchEntry;
+
+ private static final Ipv4Address IPV4_ADDRESS = Ipv4Address.getDefaultInstance("1.2.3.4");
+
+ private TunIPv4SrcConvertor tunIPv4DstConvertor;
+
+ @Before
+ public void setUp() throws Exception {
+ final NxmNxTunIpv4SrcBuilder nxmNxTunIpv4SrcBuilder = new NxmNxTunIpv4SrcBuilder()
+ .setIpv4Address(IPV4_ADDRESS);
+ final NxAugMatchNotifUpdateFlowStatsBuilder nxAugMatchNotifUpdateFlowStatsBuilder = new NxAugMatchNotifUpdateFlowStatsBuilder();
+ nxAugMatchNotifUpdateFlowStatsBuilder.setNxmNxTunIpv4Src(nxmNxTunIpv4SrcBuilder.build());
+
+ final Augmentation<Extension> extensionAugmentation = nxAugMatchNotifUpdateFlowStatsBuilder.build();
+ when(extension.getAugmentation(Matchers.<Class<Augmentation<Extension>>>any())).thenReturn(extensionAugmentation);
+
+ tunIPv4DstConvertor = new TunIPv4SrcConvertor();
+ }
+
+ @Test
+ public void testConvert() throws Exception {
+ final MatchEntry matchEntry = tunIPv4DstConvertor.convert(extension);
+ Assert.assertEquals(IpConverter.Ipv4AddressToLong(IPV4_ADDRESS), ((TunIpv4SrcCaseValue)matchEntry.getMatchEntryValue()).getTunIpv4SrcValues().getValue().longValue());
+ }
+
+ @Test
+ public void testConvert1() throws Exception {
+ final TunIpv4SrcValuesBuilder tunIpv4SrcValuesBuilder = new TunIpv4SrcValuesBuilder()
+ .setValue(IpConverter.Ipv4AddressToLong(IPV4_ADDRESS));
+ final TunIpv4SrcCaseValueBuilder tunIpv4SrcCaseValueBuilder = new TunIpv4SrcCaseValueBuilder()
+ .setTunIpv4SrcValues(tunIpv4SrcValuesBuilder.build());
+
+ final TunIpv4SrcCaseValue tunIpv4SrcCaseValue = tunIpv4SrcCaseValueBuilder.build();
+
+ when(matchEntry.getMatchEntryValue()).thenReturn(tunIpv4SrcCaseValue);
+
+ final ExtensionAugment<? extends Augmentation<Extension>> extensionAugment = tunIPv4DstConvertor.convert(matchEntry, MatchPath.PACKETRECEIVED_MATCH);
+ Assert.assertEquals(IPV4_ADDRESS, ((NxAugMatchNotifPacketIn)extensionAugment.getAugmentationObject()).getNxmNxTunIpv4Src().getIpv4Address());
+ Assert.assertEquals(extensionAugment.getKey(), NxmNxTunIpv4SrcKey.class);
+
+ final ExtensionAugment<? extends Augmentation<Extension>> extensionAugment1 = tunIPv4DstConvertor.convert(matchEntry, MatchPath.SWITCHFLOWREMOVED_MATCH);
+ Assert.assertEquals(IPV4_ADDRESS, ((NxAugMatchNotifSwitchFlowRemoved)extensionAugment1.getAugmentationObject()).getNxmNxTunIpv4Src().getIpv4Address());
+ Assert.assertEquals(extensionAugment.getKey(), NxmNxTunIpv4SrcKey.class);
+
+ final ExtensionAugment<? extends Augmentation<Extension>> extensionAugment2 = tunIPv4DstConvertor.convert(matchEntry, MatchPath.FLOWSSTATISTICSUPDATE_FLOWANDSTATISTICSMAPLIST_MATCH);
+ Assert.assertEquals(IPV4_ADDRESS, ((NxAugMatchNotifUpdateFlowStats)extensionAugment2.getAugmentationObject()).getNxmNxTunIpv4Src().getIpv4Address());
+ Assert.assertEquals(extensionAugment.getKey(), NxmNxTunIpv4SrcKey.class);
+ }
+
+}
\ No newline at end of file
--- /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.extension.vendor.nicira.convertor.match;
+
+import static org.mockito.Mockito.when;
+
+import java.math.BigInteger;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Matchers;
+import org.mockito.Mock;
+import org.mockito.runners.MockitoJUnitRunner;
+import org.opendaylight.openflowplugin.extension.api.ExtensionAugment;
+import org.opendaylight.openflowplugin.extension.api.path.MatchPath;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntry;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.ofj.nxm.nx.match.tun.id.grouping.TunIdValuesBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.oxm.container.match.entry.value.TunIdCaseValue;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.oxm.container.match.entry.value.TunIdCaseValueBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.general.rev140714.general.extension.grouping.Extension;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchNotifPacketIn;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchNotifSwitchFlowRemoved;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchNotifUpdateFlowStats;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchNotifUpdateFlowStatsBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxmNxTunIdKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.nxm.nx.tun.id.grouping.NxmNxTunIdBuilder;
+import org.opendaylight.yangtools.yang.binding.Augmentation;
+
+/**
+ * Test for {@link TunIdConvertor}.
+ */
+@RunWith(MockitoJUnitRunner.class)
+public class TunIdConvertorTest {
+ @Mock
+ private Extension extension;
+ @Mock
+ private MatchEntry matchEntry;
+
+ private TunIdConvertor tunIdConvertor;
+
+ @Before
+ public void setUp() throws Exception {
+ final NxmNxTunIdBuilder nxmNxTunIdBuilder = new NxmNxTunIdBuilder()
+ .setValue(BigInteger.ONE);
+ final NxAugMatchNotifUpdateFlowStatsBuilder nxAugMatchNotifUpdateFlowStatsBuilder = new NxAugMatchNotifUpdateFlowStatsBuilder();
+ nxAugMatchNotifUpdateFlowStatsBuilder.setNxmNxTunId(nxmNxTunIdBuilder.build());
+
+ final Augmentation<Extension> extensionAugmentation = nxAugMatchNotifUpdateFlowStatsBuilder.build();
+ when(extension.getAugmentation(Matchers.<Class<Augmentation<Extension>>>any())).thenReturn(extensionAugmentation);
+
+ tunIdConvertor = new TunIdConvertor();
+ }
+
+ @Test
+ public void testConvert() throws Exception {
+ final MatchEntry matchEntry = tunIdConvertor.convert(extension);
+ Assert.assertEquals(BigInteger.ONE, ((TunIdCaseValue)matchEntry.getMatchEntryValue()).getTunIdValues().getValue());
+ }
+
+ @Test
+ public void testConvert1() throws Exception {
+ final TunIdValuesBuilder tunIdValuesBuilder = new TunIdValuesBuilder()
+ .setValue(BigInteger.TEN);
+ final TunIdCaseValueBuilder tunIdCaseValueBuilder = new TunIdCaseValueBuilder()
+ .setTunIdValues(tunIdValuesBuilder.build());
+
+ final TunIdCaseValue tunIdCaseValue = tunIdCaseValueBuilder.build();
+
+ when(matchEntry.getMatchEntryValue()).thenReturn(tunIdCaseValue);
+
+ final ExtensionAugment<? extends Augmentation<Extension>> extensionAugment = tunIdConvertor.convert(matchEntry, MatchPath.PACKETRECEIVED_MATCH);
+ Assert.assertEquals(BigInteger.TEN, ((NxAugMatchNotifPacketIn)extensionAugment.getAugmentationObject()).getNxmNxTunId().getValue());
+ Assert.assertEquals(extensionAugment.getKey(), NxmNxTunIdKey.class);
+
+ final ExtensionAugment<? extends Augmentation<Extension>> extensionAugment1 = tunIdConvertor.convert(matchEntry, MatchPath.SWITCHFLOWREMOVED_MATCH);
+ Assert.assertEquals(BigInteger.TEN, ((NxAugMatchNotifSwitchFlowRemoved)extensionAugment1.getAugmentationObject()).getNxmNxTunId().getValue());
+ Assert.assertEquals(extensionAugment.getKey(), NxmNxTunIdKey.class);
+
+ final ExtensionAugment<? extends Augmentation<Extension>> extensionAugment2 = tunIdConvertor.convert(matchEntry, MatchPath.FLOWSSTATISTICSUPDATE_FLOWANDSTATISTICSMAPLIST_MATCH);
+ Assert.assertEquals(BigInteger.TEN, ((NxAugMatchNotifUpdateFlowStats)extensionAugment2.getAugmentationObject()).getNxmNxTunId().getValue());
+ Assert.assertEquals(extensionAugment.getKey(), NxmNxTunIdKey.class);
+ }
+
+}
\ No newline at end of file
--- /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.extension.vendor.nicira.convertor.match;
+
+import static org.mockito.Mockito.when;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Matchers;
+import org.mockito.Mock;
+import org.mockito.runners.MockitoJUnitRunner;
+import org.opendaylight.openflowplugin.extension.api.ExtensionAugment;
+import org.opendaylight.openflowplugin.extension.api.path.MatchPath;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.PortNumber;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntry;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.ofj.nxm.of.match.udp.dst.grouping.UdpDstValuesBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.oxm.container.match.entry.value.UdpDstCaseValue;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.oxm.container.match.entry.value.UdpDstCaseValueBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.general.rev140714.general.extension.grouping.Extension;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchNotifPacketIn;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchNotifSwitchFlowRemoved;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchNotifUpdateFlowStats;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchNotifUpdateFlowStatsBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxmOfUdpDstKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.nxm.of.udp.dst.grouping.NxmOfUdpDstBuilder;
+import org.opendaylight.yangtools.yang.binding.Augmentation;
+
+/**
+ * Test for {@link UdpDstConvertor}.
+ */
+@RunWith(MockitoJUnitRunner.class)
+public class UdpDstConvertorTest {
+ @Mock
+ private Extension extension;
+ @Mock
+ private MatchEntry matchEntry;
+
+ private static final PortNumber DEFAULT_PORT = new PortNumber(9999);
+
+ private UdpDstConvertor udpDstConvertor;
+
+ @Before
+ public void setUp() throws Exception {
+ final NxmOfUdpDstBuilder nxmOfUdpDstBuilder = new NxmOfUdpDstBuilder()
+ .setMask(1)
+ .setPort(DEFAULT_PORT);
+ final NxAugMatchNotifUpdateFlowStatsBuilder nxAugMatchNotifUpdateFlowStatsBuilder = new NxAugMatchNotifUpdateFlowStatsBuilder();
+ nxAugMatchNotifUpdateFlowStatsBuilder.setNxmOfUdpDst(nxmOfUdpDstBuilder.build());
+
+ final Augmentation<Extension> extensionAugmentation = nxAugMatchNotifUpdateFlowStatsBuilder.build();
+ when(extension.getAugmentation(Matchers.<Class<Augmentation<Extension>>>any())).thenReturn(extensionAugmentation);
+
+ udpDstConvertor = new UdpDstConvertor();
+ }
+
+ @Test
+ public void testConvert() throws Exception {
+ final MatchEntry matchEntry = udpDstConvertor.convert(extension);
+ Assert.assertEquals(Integer.valueOf(1), ((UdpDstCaseValue)matchEntry.getMatchEntryValue()).getUdpDstValues().getMask());
+ Assert.assertEquals(DEFAULT_PORT, ((UdpDstCaseValue)matchEntry.getMatchEntryValue()).getUdpDstValues().getPort());
+ }
+
+ @Test
+ public void testConvert1() throws Exception {
+ final UdpDstValuesBuilder udpDstValuesBuilder = new UdpDstValuesBuilder()
+ .setMask(2)
+ .setPort(DEFAULT_PORT);
+ final UdpDstCaseValueBuilder udpDstCaseValueBuilder = new UdpDstCaseValueBuilder()
+ .setUdpDstValues(udpDstValuesBuilder.build());
+
+ final UdpDstCaseValue udpDstCaseValue = udpDstCaseValueBuilder.build();
+
+ when(matchEntry.getMatchEntryValue()).thenReturn(udpDstCaseValue);
+
+ final ExtensionAugment<? extends Augmentation<Extension>> extensionAugment = udpDstConvertor.convert(matchEntry, MatchPath.PACKETRECEIVED_MATCH);
+ Assert.assertEquals(Integer.valueOf(2), ((NxAugMatchNotifPacketIn)extensionAugment.getAugmentationObject()).getNxmOfUdpDst().getMask());
+ Assert.assertEquals(DEFAULT_PORT, ((NxAugMatchNotifPacketIn)extensionAugment.getAugmentationObject()).getNxmOfUdpDst().getPort());
+ Assert.assertEquals(extensionAugment.getKey(), NxmOfUdpDstKey.class);
+
+ final ExtensionAugment<? extends Augmentation<Extension>> extensionAugment1 = udpDstConvertor.convert(matchEntry, MatchPath.SWITCHFLOWREMOVED_MATCH);
+ Assert.assertEquals(Integer.valueOf(2), ((NxAugMatchNotifSwitchFlowRemoved)extensionAugment1.getAugmentationObject()).getNxmOfUdpDst().getMask());
+ Assert.assertEquals(DEFAULT_PORT, ((NxAugMatchNotifSwitchFlowRemoved)extensionAugment1.getAugmentationObject()).getNxmOfUdpDst().getPort());
+ Assert.assertEquals(extensionAugment.getKey(), NxmOfUdpDstKey.class);
+
+ final ExtensionAugment<? extends Augmentation<Extension>> extensionAugment2 = udpDstConvertor.convert(matchEntry, MatchPath.FLOWSSTATISTICSUPDATE_FLOWANDSTATISTICSMAPLIST_MATCH);
+ Assert.assertEquals(Integer.valueOf(2), ((NxAugMatchNotifUpdateFlowStats)extensionAugment2.getAugmentationObject()).getNxmOfUdpDst().getMask());
+ Assert.assertEquals(DEFAULT_PORT, ((NxAugMatchNotifUpdateFlowStats)extensionAugment2.getAugmentationObject()).getNxmOfUdpDst().getPort());
+ Assert.assertEquals(extensionAugment.getKey(), NxmOfUdpDstKey.class);
+ }
+
+}
\ No newline at end of file
--- /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.extension.vendor.nicira.convertor.match;
+
+import static org.mockito.Mockito.when;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Matchers;
+import org.mockito.Mock;
+import org.mockito.runners.MockitoJUnitRunner;
+import org.opendaylight.openflowplugin.extension.api.ExtensionAugment;
+import org.opendaylight.openflowplugin.extension.api.path.MatchPath;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.PortNumber;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntry;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.ofj.nxm.of.match.udp.src.grouping.UdpSrcValuesBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.oxm.container.match.entry.value.UdpSrcCaseValue;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.oxm.container.match.entry.value.UdpSrcCaseValueBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.general.rev140714.general.extension.grouping.Extension;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchNotifPacketIn;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchNotifSwitchFlowRemoved;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchNotifUpdateFlowStats;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchNotifUpdateFlowStatsBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxmOfUdpSrcKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.nxm.of.udp.src.grouping.NxmOfUdpSrcBuilder;
+import org.opendaylight.yangtools.yang.binding.Augmentation;
+
+/**
+ * Test for {@link UdpSrcConvertor}.
+ */
+@RunWith(MockitoJUnitRunner.class)
+public class UdpSrcConvertorTest {
+ @Mock
+ private Extension extension;
+ @Mock
+ private MatchEntry matchEntry;
+
+ private static final PortNumber DEFAULT_PORT = new PortNumber(9999);
+
+ private UdpSrcConvertor udpSrcConvertor;
+
+ @Before
+ public void setUp() throws Exception {
+ final NxmOfUdpSrcBuilder nxmOfUdpSrcBuilder = new NxmOfUdpSrcBuilder()
+ .setMask(1)
+ .setPort(DEFAULT_PORT);
+ final NxAugMatchNotifUpdateFlowStatsBuilder nxAugMatchNotifUpdateFlowStatsBuilder = new NxAugMatchNotifUpdateFlowStatsBuilder();
+ nxAugMatchNotifUpdateFlowStatsBuilder.setNxmOfUdpSrc(nxmOfUdpSrcBuilder.build());
+
+ final Augmentation<Extension> extensionAugmentation = nxAugMatchNotifUpdateFlowStatsBuilder.build();
+ when(extension.getAugmentation(Matchers.<Class<Augmentation<Extension>>>any())).thenReturn(extensionAugmentation);
+
+ udpSrcConvertor = new UdpSrcConvertor();
+ }
+
+ @Test
+ public void testConvert() throws Exception {
+ final MatchEntry matchEntry = udpSrcConvertor.convert(extension);
+ Assert.assertEquals(Integer.valueOf(1), ((UdpSrcCaseValue)matchEntry.getMatchEntryValue()).getUdpSrcValues().getMask());
+ Assert.assertEquals(DEFAULT_PORT, ((UdpSrcCaseValue)matchEntry.getMatchEntryValue()).getUdpSrcValues().getPort());
+ }
+
+ @Test
+ public void testConvert1() throws Exception {
+ final UdpSrcValuesBuilder udpSrcValuesBuilder = new UdpSrcValuesBuilder()
+ .setMask(2)
+ .setPort(DEFAULT_PORT);
+ final UdpSrcCaseValueBuilder udpSrcCaseValueBuilder = new UdpSrcCaseValueBuilder()
+ .setUdpSrcValues(udpSrcValuesBuilder.build());
+
+ final UdpSrcCaseValue udpSrcCaseValue = udpSrcCaseValueBuilder.build();
+
+ when(matchEntry.getMatchEntryValue()).thenReturn(udpSrcCaseValue);
+
+ final ExtensionAugment<? extends Augmentation<Extension>> extensionAugment = udpSrcConvertor.convert(matchEntry, MatchPath.PACKETRECEIVED_MATCH);
+ Assert.assertEquals(Integer.valueOf(2), ((NxAugMatchNotifPacketIn)extensionAugment.getAugmentationObject()).getNxmOfUdpSrc().getMask());
+ Assert.assertEquals(DEFAULT_PORT, ((NxAugMatchNotifPacketIn)extensionAugment.getAugmentationObject()).getNxmOfUdpSrc().getPort());
+ Assert.assertEquals(extensionAugment.getKey(), NxmOfUdpSrcKey.class);
+
+ final ExtensionAugment<? extends Augmentation<Extension>> extensionAugment1 = udpSrcConvertor.convert(matchEntry, MatchPath.SWITCHFLOWREMOVED_MATCH);
+ Assert.assertEquals(Integer.valueOf(2), ((NxAugMatchNotifSwitchFlowRemoved)extensionAugment1.getAugmentationObject()).getNxmOfUdpSrc().getMask());
+ Assert.assertEquals(DEFAULT_PORT, ((NxAugMatchNotifSwitchFlowRemoved)extensionAugment1.getAugmentationObject()).getNxmOfUdpSrc().getPort());
+ Assert.assertEquals(extensionAugment.getKey(), NxmOfUdpSrcKey.class);
+
+ final ExtensionAugment<? extends Augmentation<Extension>> extensionAugment2 = udpSrcConvertor.convert(matchEntry, MatchPath.FLOWSSTATISTICSUPDATE_FLOWANDSTATISTICSMAPLIST_MATCH);
+ Assert.assertEquals(Integer.valueOf(2), ((NxAugMatchNotifUpdateFlowStats)extensionAugment2.getAugmentationObject()).getNxmOfUdpSrc().getMask());
+ Assert.assertEquals(DEFAULT_PORT, ((NxAugMatchNotifUpdateFlowStats)extensionAugment2.getAugmentationObject()).getNxmOfUdpSrc().getPort());
+ Assert.assertEquals(extensionAugment.getKey(), NxmOfUdpSrcKey.class);
+ }
+
+}
\ No newline at end of file
}
@VisibleForTesting
- Future<RpcResult<ProcessFlatBatchOutput>> executeBatchPlan(final List<AsyncFunction<RpcResult<ProcessFlatBatchOutput>, RpcResult<ProcessFlatBatchOutput>>> batchChainElements) {
+ Future<RpcResult<ProcessFlatBatchOutput>> executeBatchPlan(final List<AsyncFunction<RpcResult<ProcessFlatBatchOutput>,
+ RpcResult<ProcessFlatBatchOutput>>> batchChainElements) {
ListenableFuture<RpcResult<ProcessFlatBatchOutput>> chainSummaryResult =
RpcResultBuilder.success(new ProcessFlatBatchOutputBuilder().build()).buildFuture();
}
return chainSummaryResult;
-
}
@VisibleForTesting
final int currentOffset = stepOffset;
chainJobs.add(new AsyncFunction<RpcResult<ProcessFlatBatchOutput>, RpcResult<ProcessFlatBatchOutput>>() {
@Override
- public ListenableFuture<RpcResult<ProcessFlatBatchOutput>> apply(final RpcResult<ProcessFlatBatchOutput> chainInput) throws Exception {
+ public ListenableFuture<RpcResult<ProcessFlatBatchOutput>> apply(final RpcResult<ProcessFlatBatchOutput> chainInput) {
if (exitOnFirstError && !chainInput.isSuccessful()) {
LOG.debug("error on flat batch chain occurred -> skipping step {}", planStep.getStepType());
return Futures.immediateFuture(chainInput);
final ListenableFuture<RpcResult<ProcessFlatBatchOutput>> chainOutput;
switch (planStep.getStepType()) {
case FLOW_ADD:
- final AddFlowsBatchInput addFlowsBatchInput = FlatBatchFlowAdapters.adaptFlatBatchAddFlow(
- planStep, node);
+ final AddFlowsBatchInput addFlowsBatchInput = FlatBatchFlowAdapters.adaptFlatBatchAddFlow(planStep, node);
final Future<RpcResult<AddFlowsBatchOutput>> resultAddFlowFuture = salFlowService.addFlowsBatch(addFlowsBatchInput);
chainOutput = FlatBatchFlowAdapters.adaptFlowBatchFutureForChain(chainInput, resultAddFlowFuture, currentOffset);
break;
case FLOW_REMOVE:
- final RemoveFlowsBatchInput removeFlowsBatchInput = FlatBatchFlowAdapters.adaptFlatBatchRemoveFlow(
- planStep, node);
+ final RemoveFlowsBatchInput removeFlowsBatchInput = FlatBatchFlowAdapters.adaptFlatBatchRemoveFlow(planStep, node);
final Future<RpcResult<RemoveFlowsBatchOutput>> resultRemoveFlowFuture = salFlowService.removeFlowsBatch(removeFlowsBatchInput);
chainOutput = FlatBatchFlowAdapters.adaptFlowBatchFutureForChain(chainInput, resultRemoveFlowFuture, currentOffset);
break;
case FLOW_UPDATE:
- final UpdateFlowsBatchInput updateFlowsBatchInput = FlatBatchFlowAdapters.adaptFlatBatchUpdateFlow(
- planStep, node);
+ final UpdateFlowsBatchInput updateFlowsBatchInput = FlatBatchFlowAdapters.adaptFlatBatchUpdateFlow(planStep, node);
final Future<RpcResult<UpdateFlowsBatchOutput>> resultUpdateFlowFuture = salFlowService.updateFlowsBatch(updateFlowsBatchInput);
chainOutput = FlatBatchFlowAdapters.adaptFlowBatchFutureForChain(chainInput, resultUpdateFlowFuture, currentOffset);
break;
case GROUP_ADD:
- final AddGroupsBatchInput addGroupsBatchInput = FlatBatchGroupAdapters.adaptFlatBatchAddGroup(
- planStep, node);
+ final AddGroupsBatchInput addGroupsBatchInput = FlatBatchGroupAdapters.adaptFlatBatchAddGroup(planStep, node);
final Future<RpcResult<AddGroupsBatchOutput>> resultAddGroupFuture = salGroupService.addGroupsBatch(addGroupsBatchInput);
chainOutput = FlatBatchGroupAdapters.adaptGroupBatchFutureForChain(chainInput, resultAddGroupFuture, currentOffset);
break;
case GROUP_REMOVE:
- final RemoveGroupsBatchInput removeGroupsBatchInput = FlatBatchGroupAdapters.adaptFlatBatchRemoveGroup(
- planStep, node);
+ final RemoveGroupsBatchInput removeGroupsBatchInput = FlatBatchGroupAdapters.adaptFlatBatchRemoveGroup(planStep, node);
final Future<RpcResult<RemoveGroupsBatchOutput>> resultRemoveGroupFuture = salGroupService.removeGroupsBatch(removeGroupsBatchInput);
chainOutput = FlatBatchGroupAdapters.adaptGroupBatchFutureForChain(chainInput, resultRemoveGroupFuture, currentOffset);
break;
case GROUP_UPDATE:
- final UpdateGroupsBatchInput updateGroupsBatchInput = FlatBatchGroupAdapters.adaptFlatBatchUpdateGroup(
- planStep, node);
+ final UpdateGroupsBatchInput updateGroupsBatchInput = FlatBatchGroupAdapters.adaptFlatBatchUpdateGroup(planStep, node);
final Future<RpcResult<UpdateGroupsBatchOutput>> resultUpdateGroupFuture = salGroupService.updateGroupsBatch(updateGroupsBatchInput);
chainOutput = FlatBatchGroupAdapters.adaptGroupBatchFutureForChain(chainInput, resultUpdateGroupFuture, currentOffset);
break;
case METER_ADD:
- final AddMetersBatchInput addMetersBatchInput = FlatBatchMeterAdapters.adaptFlatBatchAddMeter(
- planStep, node);
+ final AddMetersBatchInput addMetersBatchInput = FlatBatchMeterAdapters.adaptFlatBatchAddMeter(planStep, node);
final Future<RpcResult<AddMetersBatchOutput>> resultAddMeterFuture = salMeterService.addMetersBatch(addMetersBatchInput);
chainOutput = FlatBatchMeterAdapters.adaptMeterBatchFutureForChain(chainInput, resultAddMeterFuture, currentOffset);
break;
case METER_REMOVE:
- final RemoveMetersBatchInput removeMetersBatchInput = FlatBatchMeterAdapters.adaptFlatBatchRemoveMeter(
- planStep, node);
+ final RemoveMetersBatchInput removeMetersBatchInput = FlatBatchMeterAdapters.adaptFlatBatchRemoveMeter(planStep, node);
final Future<RpcResult<RemoveMetersBatchOutput>> resultRemoveMeterFuture = salMeterService.removeMetersBatch(removeMetersBatchInput);
chainOutput = FlatBatchMeterAdapters.adaptMeterBatchFutureForChain(chainInput, resultRemoveMeterFuture, currentOffset);
break;
case METER_UPDATE:
- final UpdateMetersBatchInput updateMetersBatchInput = FlatBatchMeterAdapters.adaptFlatBatchUpdateMeter(
- planStep, node);
+ final UpdateMetersBatchInput updateMetersBatchInput = FlatBatchMeterAdapters.adaptFlatBatchUpdateMeter(planStep, node);
final Future<RpcResult<UpdateMetersBatchOutput>> resultUpdateMeterFuture = salMeterService.updateMetersBatch(updateMetersBatchInput);
chainOutput = FlatBatchMeterAdapters.adaptMeterBatchFutureForChain(chainInput, resultUpdateMeterFuture, currentOffset);
break;