import java.util.Map;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey;
+import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
/**
* Created by Martin Bobak <mbobak@cisco.com> on 8.4.2015.
*/
public interface DeviceFlowRegistry extends AutoCloseable {
+ void fill(KeyedInstanceIdentifier<Node, NodeKey> instanceIdentifier);
+
FlowDescriptor retrieveIdForFlow(FlowRegistryKey flowRegistryKey);
void store(FlowRegistryKey flowRegistryKey, FlowDescriptor flowDescriptor);
- FlowId storeIfNecessary(FlowRegistryKey flowRegistryKey, short tableId);
+ FlowId storeIfNecessary(FlowRegistryKey flowRegistryKey);
void markToBeremoved(FlowRegistryKey flowRegistryKey);
package org.opendaylight.openflowplugin.api.openflow.registry.flow;
import java.math.BigInteger;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Match;
/**
* Marker interface identifying flow stored in OFP local flow registry.
BigInteger getCookie();
-
+ Match getMatch();
}
notificationPublishService,
new AtomicLong());
}
+
+ // Fill flow registry with flows found in operational and config datastore
+ deviceContext.getDeviceFlowRegistry().fill(deviceInfo.getNodeInstanceIdentifier());
} else {
logText = "Stopp";
statisticsManager.stopScheduling(deviceInfo);
deviceInfo = primaryConnectionContext.getDeviceInfo();
this.transactionChainManager = new TransactionChainManager(dataBroker, deviceInfo, conductor);
auxiliaryConnectionContexts = new HashMap<>();
- deviceFlowRegistry = new DeviceFlowRegistryImpl();
+ deviceFlowRegistry = new DeviceFlowRegistryImpl(dataBroker);
deviceGroupRegistry = new DeviceGroupRegistryImpl();
deviceMeterRegistry = new DeviceMeterRegistryImpl();
messageSpy = conductor.getMessageIntelligenceAgency();
*/
package org.opendaylight.openflowplugin.impl.registry.flow;
+import com.google.common.base.Optional;
+import com.google.common.util.concurrent.CheckedFuture;
import com.romix.scala.collection.concurrent.TrieMap;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
+import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentMap;
+import java.util.concurrent.ExecutionException;
import javax.annotation.concurrent.GuardedBy;
+import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction;
+import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
import org.opendaylight.openflowplugin.api.openflow.registry.flow.DeviceFlowRegistry;
import org.opendaylight.openflowplugin.api.openflow.registry.flow.FlowDescriptor;
import org.opendaylight.openflowplugin.api.openflow.registry.flow.FlowRegistryKey;
import org.opendaylight.openflowplugin.impl.util.FlowUtil;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.Table;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
private final ConcurrentMap<FlowRegistryKey, FlowDescriptor> flowRegistry = new TrieMap<>();
@GuardedBy("marks")
private final Collection<FlowRegistryKey> marks = new HashSet<>();
+ private final DataBroker dataBroker;
+
+ public DeviceFlowRegistryImpl(final DataBroker dataBroker) {
+ this.dataBroker = dataBroker;
+ }
+
+ @Override
+ public void fill(final KeyedInstanceIdentifier<Node, NodeKey> instanceIdentifier) {
+ LOG.trace("Filling flow registry with flows for node: {}", instanceIdentifier);
+
+ // Prepare path for read transaction
+ // TODO: Read only Tables, and not entire FlowCapableNode (fix Yang model)
+ final InstanceIdentifier<FlowCapableNode> path = instanceIdentifier.augmentation(FlowCapableNode.class);
+
+ // First, try to fill registry with flows from DS/Configuration
+ fillFromDatastore(LogicalDatastoreType.CONFIGURATION, path);
+
+ // Now, try to fill registry with flows from DS/Operational
+ // in case of cluster fail over, when clients are not using DS/Configuration
+ // for adding flows, but only RPCs
+ fillFromDatastore(LogicalDatastoreType.OPERATIONAL, path);
+ }
+
+ private void fillFromDatastore(final LogicalDatastoreType logicalDatastoreType, final InstanceIdentifier<FlowCapableNode> path) {
+ // Create new read-only transaction
+ final ReadOnlyTransaction transaction = dataBroker.newReadOnlyTransaction();
+
+ // Bail out early if transaction is null
+ if (transaction == null) {
+ return;
+ }
+
+ // Prepare read operation from datastore for path
+ final CheckedFuture<Optional<FlowCapableNode>, ReadFailedException> future =
+ transaction.read(logicalDatastoreType, path);
+
+ // Bail out early if future is null
+ if (future == null) {
+ return;
+ }
+
+ try {
+ // Synchronously read all data in path
+ final Optional<FlowCapableNode> data = future.get();
+
+ if (data.isPresent()) {
+ final List<Table> tables = data.get().getTable();
+
+ if (tables != null) {
+ for (Table table : tables) {
+ final List<Flow> flows = table.getFlow();
+
+ if (flows != null) {
+ // If we finally got some flows, store each of them in registry if needed
+ for (Flow flow : table.getFlow()) {
+ final FlowRegistryKey key = FlowRegistryKeyFactory.create(flow);
+
+ // Now, we will update the registry, but we will also try to prevent duplicate entries
+ if (!flowRegistry.containsKey(key)) {
+ LOG.trace("Reading and storing flowDescriptor with table ID : {} and flow ID : {}",
+ flow.getTableId(),
+ flow.getId().getValue());
+
+ final FlowDescriptor descriptor = FlowDescriptorFactory.create(
+ flow.getTableId(),
+ flow.getId());
+
+ flowRegistry.put(key, descriptor);
+ }
+ }
+ }
+ }
+ }
+ }
+ } catch (InterruptedException | ExecutionException e) {
+ LOG.error("Read transaction for identifier {} failed with exception: {}", path, e);
+ }
+
+ // After we are done with reading from datastore, close the transaction
+ transaction.close();
+ }
@Override
public FlowDescriptor retrieveIdForFlow(final FlowRegistryKey flowRegistryKey) {
+ LOG.trace("Trying to retrieve flowDescriptor for flow hash: {}", flowRegistryKey.hashCode());
+
+ // First, try to get FlowDescriptor from flow registry
FlowDescriptor flowDescriptor = flowRegistry.get(flowRegistryKey);
+
+ // We was not able to retrieve FlowDescriptor, so we will at least try to generate it
+ if (flowDescriptor == null) {
+ final short tableId = flowRegistryKey.getTableId();
+ final FlowId alienFlowId = FlowUtil.createAlienFlowId(tableId);
+ flowDescriptor = FlowDescriptorFactory.create(tableId, alienFlowId);
+
+ // Finally we got flowDescriptor, so now we will store it to registry,
+ // so next time we won't need to generate it again
+ store(flowRegistryKey, flowDescriptor);
+ }
+
return flowDescriptor;
}
}
@Override
- public FlowId storeIfNecessary(final FlowRegistryKey flowRegistryKey, @Deprecated final short tableId) {
- //TODO: remove tableId parameter - it is contained in the first one
- final FlowId alienFlowId = FlowUtil.createAlienFlowId(tableId);
- final FlowDescriptor alienFlowDescriptor = FlowDescriptorFactory.create(tableId, alienFlowId);
-
- final FlowDescriptor previous = flowRegistry.putIfAbsent(flowRegistryKey, alienFlowDescriptor);
- if (previous == null) {
- LOG.trace("Flow descriptor for flow hash {} wasn't found.", flowRegistryKey.hashCode());
- return alienFlowId;
- } else {
- return previous.getFlowId();
- }
+ public FlowId storeIfNecessary(final FlowRegistryKey flowRegistryKey) {
+ // We will simply reuse retrieveIdForFlow to get or generate FlowDescriptor and store it if needed
+ final FlowDescriptor flowDescriptor = retrieveIdForFlow(flowRegistryKey);
+ return flowDescriptor.getFlowId();
}
@Override
if (this == o) {
return true;
}
- if (o == null || getClass() != o.getClass()) {
- return false;
- }
-
- final FlowRegistryKeyDto that = (FlowRegistryKeyDto) o;
- if (priority != that.priority) {
- return false;
- }
- if (tableId != that.tableId) {
- return false;
- }
- if (!match.equals(that.match)) {
+ if (o == null || !(o instanceof FlowRegistryKey)) {
return false;
}
- return true;
+ final FlowRegistryKey that = (FlowRegistryKey) o;
+
+ return getPriority() == that.getPriority() &&
+ getTableId() == that.getTableId() &&
+ getMatch().equals(that.getMatch());
}
@Override
public BigInteger getCookie() {
return cookie;
}
+
+ @Override
+ public Match getMatch() {
+ return match;
+ }
}
}
final short tableId = flowStat.getTableId();
final FlowRegistryKey flowRegistryKey = FlowRegistryKeyFactory.create(flowBuilder.build());
- final FlowId flowId = registry.storeIfNecessary(flowRegistryKey, tableId);
+ final FlowId flowId = registry.storeIfNecessary(flowRegistryKey);
final FlowKey flowKey = new FlowKey(flowId);
flowBuilder.setKey(flowKey);
final FlowBuilder flowBuilder = new FlowBuilder(flowStatistics)
.addAugmentation(FlowStatisticsData.class, flowStatisticsDataBld.build());
- final short tableId = flowStatistics.getTableId();
final FlowRegistryKey flowRegistryKey = FlowRegistryKeyFactory.create(flowBuilder.build());
- return getDeviceRegistry().getDeviceFlowRegistry().storeIfNecessary(flowRegistryKey, tableId);
+ return getDeviceRegistry().getDeviceFlowRegistry().storeIfNecessary(flowRegistryKey);
}
}
private static final RpcResultBuilder<List<BatchFailedFlowsOutput>> SUCCESSFUL_FLOW_OUTPUT_RPC_RESULT =
RpcResultBuilder.success(Collections.<BatchFailedFlowsOutput>emptyList());
- /** Attach barrier response to given {@link RpcResult}<RemoveFlowsBatchOutput> */
+ /**
+ * Attach barrier response to given {@link RpcResult}<RemoveFlowsBatchOutput>
+ */
public static final Function<Pair<RpcResult<RemoveFlowsBatchOutput>, RpcResult<Void>>, RpcResult<RemoveFlowsBatchOutput>>
FLOW_REMOVE_COMPOSING_TRANSFORM = createComposingFunction();
- /** Attach barrier response to given {@link RpcResult}<AddFlowsBatchOutput> */
+ /**
+ * Attach barrier response to given {@link RpcResult}<AddFlowsBatchOutput>
+ */
public static final Function<Pair<RpcResult<AddFlowsBatchOutput>, RpcResult<Void>>, RpcResult<AddFlowsBatchOutput>>
FLOW_ADD_COMPOSING_TRANSFORM = createComposingFunction();
- /** Attach barrier response to given {@link RpcResult}<UpdateFlowsBatchOutput> */
+ /**
+ * Attach barrier response to given {@link RpcResult}<UpdateFlowsBatchOutput>
+ */
public static final Function<Pair<RpcResult<UpdateFlowsBatchOutput>, RpcResult<Void>>, RpcResult<UpdateFlowsBatchOutput>>
FLOW_UPDATE_COMPOSING_TRANSFORM = createComposingFunction();
return resultBld;
}
+ /**
+ * Create alien flow id
+ *
+ * @param tableId the table id
+ * @return the flow id
+ */
public static FlowId createAlienFlowId(final short tableId) {
final StringBuilder sBuilder = new StringBuilder(ALIEN_SYSTEM_FLOW_ID)
.append(tableId).append('-').append(unaccountedFlowsCounter.incrementAndGet());
}
/**
+ * Build flow path flow ref.
+ *
* @param nodePath path to {@link Node}
* @param tableId path to {@link Table} under {@link Node}
* @param flowId path to {@link Flow} under {@link Table}
* Factory method: creates {@link Function} which keeps info of original inputs (passed to flow-rpc) and processes
* list of all flow-rpc results.
*
- * @param inputBatchFlows collection of problematic flow-ids wrapped in container of given type <O>
* @param <O> result container type
+ * @param inputBatchFlows collection of problematic flow-ids wrapped in container of given type <O>
* @return static reusable function
*/
public static <O> Function<List<RpcResult<O>>, RpcResult<List<BatchFailedFlowsOutput>>> createCumulatingFunction(
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
+import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.runners.MockitoJUnitRunner;
+import org.opendaylight.controller.md.sal.binding.api.DataBroker;
import org.opendaylight.openflowplugin.api.openflow.connection.ConnectionContext;
import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
import org.opendaylight.openflowplugin.api.openflow.device.DeviceInfo;
import org.opendaylight.openflowplugin.api.openflow.rpc.RpcManager;
import org.opendaylight.openflowplugin.api.openflow.statistics.StatisticsManager;
import org.opendaylight.openflowplugin.api.openflow.statistics.ofpspecific.MessageIntelligenceAgency;
+import org.opendaylight.openflowplugin.impl.registry.flow.DeviceFlowRegistryImpl;
import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FeaturesReply;
import org.opendaylight.yang.gen.v1.urn.opendaylight.role.service.rev150727.OfpRole;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
@RunWith(MockitoJUnitRunner.class)
public class LifecycleConductorImplTest {
@Before
public void setUp() {
+ final KeyedInstanceIdentifier<Node, NodeKey> nodeInstanceIdentifier = InstanceIdentifier.create(Nodes.class).child(Node.class, new NodeKey(nodeId));
lifecycleConductor = new LifecycleConductorImpl(messageIntelligenceAgency);
lifecycleConductor.setSafelyManager(deviceManager);
when(rpcManager.gainContext(Mockito.<DeviceInfo>any())).thenReturn(rpcContext);
when(deviceInfo.getNodeId()).thenReturn(nodeId);
when(deviceInfo.getDatapathId()).thenReturn(BigInteger.TEN);
+ when(deviceInfo.getNodeInstanceIdentifier()).thenReturn(nodeInstanceIdentifier);
when(deviceContext.getDeviceInfo()).thenReturn(deviceInfo);
when(rpcManager.gainContext(Mockito.<DeviceInfo>any())).thenReturn(rpcContext);
}
*/
@Test
public void roleChangeOnDeviceTest4() {
+ final DataBroker dataBroker = mock(DataBroker.class);
+
when(deviceContext.getDeviceState()).thenReturn(deviceState);
+ when(deviceContext.getDeviceFlowRegistry()).thenReturn(new DeviceFlowRegistryImpl(dataBroker));
when(deviceManager.gainContext(deviceInfo)).thenReturn(deviceContext);
when(deviceManager.onClusterRoleChange(deviceInfo, OfpRole.BECOMEMASTER)).thenReturn(listenableFuture);
lifecycleConductor.roleChangeOnDevice(deviceInfo,true,OfpRole.BECOMEMASTER,false);
*/
@Test
public void roleChangeOnDeviceTest5() {
+ final DataBroker dataBroker = mock(DataBroker.class);
+
when(deviceContext.getDeviceState()).thenReturn(deviceState);
+ when(deviceContext.getDeviceFlowRegistry()).thenReturn(new DeviceFlowRegistryImpl(dataBroker));
when(deviceManager.gainContext(deviceInfo)).thenReturn(deviceContext);
when(deviceManager.onClusterRoleChange(deviceInfo, OfpRole.BECOMESLAVE)).thenReturn(listenableFuture);
+
lifecycleConductor.roleChangeOnDevice(deviceInfo,true,OfpRole.BECOMESLAVE,false);
verify(statisticsManager).stopScheduling(Mockito.<DeviceInfo>any());
}
package org.opendaylight.openflowplugin.impl.registry.flow;
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import com.google.common.base.Optional;
+import com.google.common.util.concurrent.Futures;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.runners.MockitoJUnitRunner;
+import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction;
+import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
import org.opendaylight.openflowplugin.api.openflow.registry.flow.FlowDescriptor;
import org.opendaylight.openflowplugin.api.openflow.registry.flow.FlowRegistryKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowId;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.flow.and.statistics.map.list.FlowAndStatisticsMapList;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
/**
* Test for {@link DeviceFlowRegistryImpl}.
*/
+@RunWith(MockitoJUnitRunner.class)
public class DeviceFlowRegistryImplTest {
-
+ private static final String NODE_ID = "openflow:1";
private DeviceFlowRegistryImpl deviceFlowRegistry;
private FlowRegistryKey key;
private FlowDescriptor descriptor;
+ @Mock
+ private DataBroker dataBroker;
+ @Mock
+ private ReadOnlyTransaction readOnlyTransaction;
@Before
public void setUp() throws Exception {
- deviceFlowRegistry = new DeviceFlowRegistryImpl();
+ when(dataBroker.newReadOnlyTransaction()).thenReturn(readOnlyTransaction);
+ when(readOnlyTransaction.read(any(), any())).thenReturn(Futures.immediateCheckedFuture(Optional.absent()));
+ deviceFlowRegistry = new DeviceFlowRegistryImpl(dataBroker);
final FlowAndStatisticsMapList flowStats = TestFlowHelper.createFlowAndStatisticsMapListBuilder(1).build();
key = FlowRegistryKeyFactory.create(flowStats);
descriptor = FlowDescriptorFactory.create(key.getTableId(), new FlowId("ut:1"));
Assert.assertEquals(1, deviceFlowRegistry.getAllFlowDescriptors().size());
}
+ @Test
+ public void testFill() throws Exception {
+ final KeyedInstanceIdentifier<Node, NodeKey> nodeInstanceIdentifier = InstanceIdentifier.create(Nodes.class).child(Node.class, new NodeKey(new NodeId(NODE_ID)));
+ final InstanceIdentifier<FlowCapableNode> path = nodeInstanceIdentifier.augmentation(FlowCapableNode.class);
+
+ deviceFlowRegistry.fill(nodeInstanceIdentifier);
+
+ verify(dataBroker, times(2)).newReadOnlyTransaction();
+ verify(readOnlyTransaction).read(LogicalDatastoreType.CONFIGURATION, path);
+ verify(readOnlyTransaction).read(LogicalDatastoreType.OPERATIONAL, path);
+ }
+
@Test
public void testRetrieveIdForFlow() throws Exception {
Assert.assertEquals(descriptor, deviceFlowRegistry.retrieveIdForFlow(key));
FlowId newFlowId;
//store existing key
- newFlowId = deviceFlowRegistry.storeIfNecessary(key, key.getTableId());
+ newFlowId = deviceFlowRegistry.storeIfNecessary(key);
Assert.assertEquals(1, deviceFlowRegistry.getAllFlowDescriptors().size());
Assert.assertEquals(descriptor, deviceFlowRegistry.retrieveIdForFlow(key));
//store new key
final String alienPrefix = "#UF$TABLE*2-";
final FlowRegistryKey key2 = FlowRegistryKeyFactory.create(TestFlowHelper.createFlowAndStatisticsMapListBuilder(2).build());
- newFlowId = deviceFlowRegistry.storeIfNecessary(key2, key2.getTableId());
+ newFlowId = deviceFlowRegistry.storeIfNecessary(key2);
Assert.assertTrue(newFlowId.getValue().startsWith(alienPrefix));
Assert.assertTrue(deviceFlowRegistry.retrieveIdForFlow(key2).getFlowId().getValue().startsWith(alienPrefix));
verify(mockedReadOnlyTx, times(1)).read(LogicalDatastoreType.OPERATIONAL, nodePath);
verify(mockedReadOnlyTx, times(1)).close();
- verify(mockedFlowRegistry).storeIfNecessary(Matchers.<FlowRegistryKey> any(), Matchers.anyShort());
+ verify(mockedFlowRegistry).storeIfNecessary(Matchers.<FlowRegistryKey> any());
verify(mockedDeviceContext, times(1)).writeToTransaction(eq(LogicalDatastoreType.OPERATIONAL),
eq(tableIdent), Matchers.<Table> any());
/*
assertNotNull(actualResult.getResult());
assertTrue(actualResult.getResult().isEmpty());
- Mockito.verify(mockedFlowRegistry, Mockito.never()).storeIfNecessary(Matchers.<FlowRegistryKey>any(), Matchers.anyShort());
+ Mockito.verify(mockedFlowRegistry, Mockito.never()).storeIfNecessary(Matchers.any());
Mockito.verify(mockedDeviceContext, Mockito.never()).writeToTransaction(Matchers.eq(LogicalDatastoreType.OPERATIONAL),
Matchers.<InstanceIdentifier>any(), Matchers.<DataObject>any());
}
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;
import java.math.BigInteger;
-import java.util.List;
import org.junit.Before;
import org.junit.runner.RunWith;
import org.mockito.Matchers;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
+import org.opendaylight.controller.md.sal.binding.api.DataBroker;
import org.opendaylight.openflowjava.protocol.api.connection.ConnectionAdapter;
import org.opendaylight.openflowjava.protocol.api.connection.OutboundQueue;
import org.opendaylight.openflowplugin.api.OFConstants;
import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FeaturesReply;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesOutput;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReply;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
import org.opendaylight.yangtools.yang.common.RpcResult;
private static final KeyedInstanceIdentifier<Node, NodeKey> NODE_II
= InstanceIdentifier.create(Nodes.class).child(Node.class, new NodeKey(new NodeId(DUMMY_NODE_ID)));
-
@Mock
protected RequestContextStack mockedRequestContextStack;
@Mock
protected OutboundQueue mockedOutboundQueue;
@Mock
protected MultiMsgCollector multiMessageCollector;
+ @Mock
+ protected DataBroker dataBroker;
@Before
public void initialization() {
when(mockedDeviceContext.getPrimaryConnectionContext()).thenReturn(mockedPrimConnectionContext);
when(mockedDeviceContext.getMessageSpy()).thenReturn(mockedMessagSpy);
- when(mockedDeviceContext.getDeviceFlowRegistry()).thenReturn(new DeviceFlowRegistryImpl());
+ when(mockedDeviceContext.getDeviceFlowRegistry()).thenReturn(new DeviceFlowRegistryImpl(dataBroker));
when(mockedDeviceContext.getDeviceState()).thenReturn(mockedDeviceState);
when(mockedDeviceContext.getDeviceInfo()).thenReturn(mockedDeviceInfo);
- when(mockedDeviceContext.getMultiMsgCollector(Matchers.<RequestContext<List<MultipartReply>>>any())).thenReturn(multiMessageCollector);
+ when(mockedDeviceContext.getMultiMsgCollector(Matchers.any())).thenReturn(multiMessageCollector);
setup();
}
public void testGatherStatistics_flow() throws Exception {
final short tableId = 0;
final MultipartType type = MultipartType.OFPMPFLOW;
- when(deviceFlowRegistry.storeIfNecessary(Matchers.any(FlowRegistryKey.class), Matchers.anyShort()))
+ when(deviceFlowRegistry.storeIfNecessary(Matchers.any(FlowRegistryKey.class)))
.thenReturn(new FlowId("openflow:21"));
final InstanceIdentifier<FlowCapableNode> nodePath = deviceInfo.getNodeInstanceIdentifier().augmentation(FlowCapableNode.class);
.child(Table.class, new TableKey((short) 0))
.child(Flow.class, new FlowKey(new FlowId("openflow:21")));
verify(deviceContext, Mockito.never()).addDeleteToTxChain(Matchers.eq(LogicalDatastoreType.OPERATIONAL), Matchers.<InstanceIdentifier<?>>any());
- verify(deviceFlowRegistry).storeIfNecessary(FlowRegistryKeyFactory.create(flowBld.build()), (short) 0);
+ verify(deviceFlowRegistry).storeIfNecessary(FlowRegistryKeyFactory.create(flowBld.build()));
verify(txFacade).writeToTransaction(Matchers.eq(LogicalDatastoreType.OPERATIONAL), Matchers.eq(flowPath), Matchers.any(Flow.class));
}
+
/**
* Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
*
import org.mockito.invocation.InvocationOnMock;
import org.mockito.runners.MockitoJUnitRunner;
import org.mockito.stubbing.Answer;
+import org.opendaylight.controller.md.sal.binding.api.DataBroker;
import org.opendaylight.controller.sal.binding.api.BindingAwareBroker;
import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;
import org.opendaylight.openflowjava.protocol.api.connection.ConnectionAdapter;
private DeviceInitializationPhaseHandler deviceInitializationPhaseHandler;
@Mock
private DeviceInfo deviceInfo;
+ @Mock
+ private DataBroker dataBroker;
private RequestContext<List<MultipartReply>> currentRequestContext;
private StatisticsManagerImpl statisticsManager;
when(mockedDeviceContext.getDeviceInfo()).thenReturn(mockedDeviceInfo);
when(mockedDeviceContext.getPrimaryConnectionContext()).thenReturn(mockedPrimConnectionContext);
when(mockedDeviceContext.getMessageSpy()).thenReturn(mockedMessagSpy);
- when(mockedDeviceContext.getDeviceFlowRegistry()).thenReturn(new DeviceFlowRegistryImpl());
+ when(mockedDeviceContext.getDeviceFlowRegistry()).thenReturn(new DeviceFlowRegistryImpl(dataBroker));
when(mockedDeviceContext.getDeviceState()).thenReturn(mockedDeviceState);
when(mockedDeviceContext.getMultiMsgCollector(
Matchers.<RequestContext<List<MultipartReply>>>any())).thenAnswer(
public void setUp() throws Exception {
service = new FlowDirectStatisticsService(requestContextStack, deviceContext);
final DeviceFlowRegistry registry = mock(DeviceFlowRegistry.class);
- when(registry.storeIfNecessary(any(), eq(TABLE_NO))).thenReturn(new FlowId("1"));
+ when(registry.storeIfNecessary(any())).thenReturn(new FlowId("1"));
when(deviceContext.getDeviceFlowRegistry()).thenReturn(registry);
}