use of org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNodeBuilder in project openflowplugin by opendaylight.
the class SyncReactorImplTest method testSyncup.
@Test
public void testSyncup() throws Exception {
final FlowCapableNode configFcn = new FlowCapableNodeBuilder().setGroup(Collections.singletonList(DSInputFactory.createGroup(1L))).setTable(Collections.singletonList(new TableBuilder().setFlow(Collections.singletonList(DSInputFactory.createFlow("f1", 1))).build())).setMeter(Collections.singletonList(DSInputFactory.createMeter(1L))).build();
final FlowCapableNode operationalFcn = new FlowCapableNodeBuilder().setGroup(Collections.singletonList(DSInputFactory.createGroup(2L))).setTable(Collections.singletonList(new TableBuilder().setFlow(Collections.singletonList(DSInputFactory.createFlow("f2", 2))).build())).setMeter(Collections.singletonList(DSInputFactory.createMeter(2L))).build();
final SyncupEntry syncupEntry = new SyncupEntry(configFcn, LogicalDatastoreType.CONFIGURATION, operationalFcn, LogicalDatastoreType.OPERATIONAL);
Mockito.when(syncPlanPushStrategy.executeSyncStrategy(Matchers.<ListenableFuture<RpcResult<Void>>>any(), Matchers.<SynchronizationDiffInput>any(), Matchers.<SyncCrudCounters>any())).thenReturn(RpcResultBuilder.<Void>success().buildFuture());
final ListenableFuture<Boolean> syncupResult = reactor.syncup(NODE_IDENT, syncupEntry);
Assert.assertTrue(syncupResult.isDone());
final Boolean voidRpcResult = syncupResult.get(2, TimeUnit.SECONDS);
Assert.assertTrue(voidRpcResult);
Mockito.verify(syncPlanPushStrategy).executeSyncStrategy(Matchers.<ListenableFuture<RpcResult<Void>>>any(), syncDiffInputCaptor.capture(), Matchers.<SyncCrudCounters>any());
final SynchronizationDiffInput diffInput = syncDiffInputCaptor.getValue();
Assert.assertEquals(1, ReconcileUtil.countTotalPushed(diffInput.getFlowsToAddOrUpdate().values()));
Assert.assertEquals(0, ReconcileUtil.countTotalUpdated(diffInput.getFlowsToAddOrUpdate().values()));
Assert.assertEquals(1, ReconcileUtil.countTotalPushed(diffInput.getFlowsToRemove().values()));
Assert.assertEquals(1, ReconcileUtil.countTotalPushed(diffInput.getGroupsToAddOrUpdate()));
Assert.assertEquals(0, ReconcileUtil.countTotalUpdated(diffInput.getGroupsToAddOrUpdate()));
Assert.assertEquals(1, ReconcileUtil.countTotalPushed(diffInput.getGroupsToRemove()));
Assert.assertEquals(1, diffInput.getMetersToAddOrUpdate().getItemsToPush().size());
Assert.assertEquals(0, diffInput.getMetersToAddOrUpdate().getItemsToUpdate().size());
Assert.assertEquals(1, diffInput.getMetersToRemove().getItemsToPush().size());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNodeBuilder in project openflowplugin by opendaylight.
the class StatisticsGatheringUtilsTest method testGatherStatistics_flow.
@Test
public void testGatherStatistics_flow() throws Exception {
final short tableId = 0;
final MultipartType type = MultipartType.OFPMPFLOW;
final InstanceIdentifier<FlowCapableNode> nodePath = deviceInfo.getNodeInstanceIdentifier().augmentation(FlowCapableNode.class);
final TableBuilder tableDataBld = new TableBuilder();
tableDataBld.setId(tableId);
final FlowCapableNodeBuilder flowNodeBuilder = new FlowCapableNodeBuilder();
flowNodeBuilder.setTable(Collections.singletonList(tableDataBld.build()));
final Optional<FlowCapableNode> flowNodeOpt = Optional.of(flowNodeBuilder.build());
final CheckedFuture<Optional<FlowCapableNode>, ReadFailedException> flowNodeFuture = Futures.immediateCheckedFuture(flowNodeOpt);
when(readTx.read(LogicalDatastoreType.OPERATIONAL, nodePath)).thenReturn(flowNodeFuture);
when(flowDescriptor.getFlowId()).thenReturn(flowId);
final org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.grouping.MatchBuilder matchBld = new org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.grouping.MatchBuilder().setMatchEntry(Collections.<MatchEntry>emptyList());
final FlowStatsBuilder flowStatsBld = new FlowStatsBuilder().setByteCount(BigInteger.valueOf(55L)).setPacketCount(BigInteger.valueOf(56L)).setDurationSec(57L).setDurationNsec(58L).setTableId((short) 0).setMatch(matchBld.build()).setFlags(new FlowModFlags(true, false, false, false, true));
final MultipartReplyFlowBuilder mpReplyFlowBld = new MultipartReplyFlowBuilder();
mpReplyFlowBld.setFlowStats(Lists.newArrayList(flowStatsBld.build()));
final MultipartReplyFlowCaseBuilder mpReplyFlowCaseBld = new MultipartReplyFlowCaseBuilder();
mpReplyFlowCaseBld.setMultipartReplyFlow(mpReplyFlowBld.build());
final MultipartReply flowStatsUpdated = assembleMPReplyMessage(type, mpReplyFlowCaseBld.build());
final List<MultipartReply> statsData = Collections.singletonList(flowStatsUpdated);
fireAndCheck(type, statsData);
final FlowBuilder flowBld = new FlowBuilder().setTableId((short) 0).setMatch(new MatchBuilder().build());
final KeyedInstanceIdentifier<Table, TableKey> tablePath = dummyNodePath.augmentation(FlowCapableNode.class).child(Table.class, new TableKey((short) 0));
final KeyedInstanceIdentifier<Flow, FlowKey> flowPath = tablePath.child(Flow.class, new FlowKey(flowId));
verify(deviceContext, Mockito.never()).addDeleteToTxChain(Matchers.eq(LogicalDatastoreType.OPERATIONAL), Matchers.<InstanceIdentifier<?>>any());
final InOrder inOrder = Mockito.inOrder(deviceContext);
inOrder.verify(deviceContext).writeToTransaction(Matchers.eq(LogicalDatastoreType.OPERATIONAL), Matchers.any(), Matchers.any());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNodeBuilder in project openflowplugin by opendaylight.
the class StatisticsGatheringUtilsTest method testDeleteAllKnownFlows.
@Test
public void testDeleteAllKnownFlows() throws Exception {
final short tableId = 0;
final InstanceIdentifier<FlowCapableNode> nodePath = deviceInfo.getNodeInstanceIdentifier().augmentation(FlowCapableNode.class);
final TableBuilder tableDataBld = new TableBuilder();
tableDataBld.setId(tableId);
final FlowCapableNodeBuilder flowNodeBuilder = new FlowCapableNodeBuilder();
flowNodeBuilder.setTable(Collections.singletonList(tableDataBld.build()));
final Optional<FlowCapableNode> flowNodeOpt = Optional.of(flowNodeBuilder.build());
final CheckedFuture<Optional<FlowCapableNode>, ReadFailedException> flowNodeFuture = Futures.immediateCheckedFuture(flowNodeOpt);
when(readTx.read(LogicalDatastoreType.OPERATIONAL, nodePath)).thenReturn(flowNodeFuture);
StatisticsGatheringUtils.deleteAllKnownFlows(deviceContext, deviceInfo.getNodeInstanceIdentifier().augmentation(FlowCapableNode.class), deviceFlowRegistry);
verify(deviceContext).isTransactionsEnabled();
verify(deviceContext).getReadTransaction();
verify(deviceContext).writeToTransaction(Mockito.eq(LogicalDatastoreType.OPERATIONAL), Mockito.any(), Mockito.any());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNodeBuilder in project openflowplugin by opendaylight.
the class MultipartRequestOnTheFlyCallbackTest method testOnSuccessWithValidMultipart1.
/**
* Not the last reply.
*/
@Test
public void testOnSuccessWithValidMultipart1() throws Exception {
final MatchBuilder matchBuilder = new MatchBuilder().setMatchEntry(Collections.<MatchEntry>emptyList());
final FlowStatsBuilder flowStatsBuilder = new FlowStatsBuilder().setTableId(tableId).setPriority(2).setCookie(BigInteger.ZERO).setByteCount(BigInteger.TEN).setPacketCount(BigInteger.ONE).setDurationSec(11L).setDurationNsec(12L).setMatch(matchBuilder.build()).setFlags(new FlowModFlags(true, false, false, false, false));
final MultipartReplyFlowBuilder multipartReplyFlowBuilder = new MultipartReplyFlowBuilder().setFlowStats(Collections.singletonList(flowStatsBuilder.build()));
final MultipartReplyFlowCaseBuilder multipartReplyFlowCaseBuilder = new MultipartReplyFlowCaseBuilder().setMultipartReplyFlow(multipartReplyFlowBuilder.build());
final MultipartReplyMessageBuilder mpReplyMessage = new MultipartReplyMessageBuilder().setType(MultipartType.OFPMPFLOW).setFlags(new MultipartRequestFlags(true)).setMultipartReplyBody(multipartReplyFlowCaseBuilder.build()).setXid(21L);
final InstanceIdentifier<FlowCapableNode> nodePath = mockedDeviceInfo.getNodeInstanceIdentifier().augmentation(FlowCapableNode.class);
final FlowCapableNodeBuilder flowNodeBuilder = new FlowCapableNodeBuilder();
final TableBuilder tableDataBld = new TableBuilder();
tableDataBld.setId(tableId);
flowNodeBuilder.setTable(Collections.singletonList(tableDataBld.build()));
final Optional<FlowCapableNode> flowNodeOpt = Optional.of(flowNodeBuilder.build());
final CheckedFuture<Optional<FlowCapableNode>, ReadFailedException> flowNodeFuture = Futures.immediateCheckedFuture(flowNodeOpt);
when(mockedReadOnlyTx.read(LogicalDatastoreType.OPERATIONAL, nodePath)).thenReturn(flowNodeFuture);
when(mockedDeviceContext.getReadTransaction()).thenReturn(mockedReadOnlyTx);
multipartRequestOnTheFlyCallback.onSuccess(mpReplyMessage.build());
verify(mockedReadOnlyTx, times(0)).read(LogicalDatastoreType.OPERATIONAL, nodePath);
verify(mockedReadOnlyTx, times(0)).close();
verify(mockedDeviceContext, times(1)).writeToTransaction(eq(LogicalDatastoreType.OPERATIONAL), Matchers.any(), Matchers.any());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNodeBuilder in project openflowplugin by opendaylight.
the class MultipartRequestOnTheFlyCallbackTest method initialization.
@Before
public void initialization() {
when(mockedDeviceContext.getMessageSpy()).thenReturn(new MessageIntelligenceAgencyImpl());
when(mockedNodeId.toString()).thenReturn(DUMMY_NODE_ID);
when(mockedPrimaryConnection.getNodeId()).thenReturn(mockedNodeId);
when(mockedPrimaryConnection.getFeatures()).thenReturn(mockedFeaturesReply);
when(mockedFeaturesReply.getVersion()).thenReturn(OFConstants.OFP_VERSION_1_3);
when(mockedFeaturesReply.getDatapathId()).thenReturn(BigInteger.valueOf(123L));
when(mocketGetFeaturesOutput.getTables()).thenReturn(tableId);
when(mocketGetFeaturesOutput.getVersion()).thenReturn(OFConstants.OFP_VERSION_1_3);
when(mocketGetFeaturesOutput.getDatapathId()).thenReturn(BigInteger.valueOf(123L));
when(mockedDeviceContext.getPrimaryConnectionContext()).thenReturn(mockedPrimaryConnection);
when(mockedDeviceInfo.getNodeInstanceIdentifier()).thenReturn(NODE_PATH);
when(mockedDeviceInfo.getNodeId()).thenReturn(mockedNodeId);
when(mockedDeviceInfo.getDatapathId()).thenReturn(BigInteger.TEN);
when(mockedDeviceInfo.getVersion()).thenReturn(OFConstants.OFP_VERSION_1_3);
when(mockedDeviceContext.getDeviceState()).thenReturn(mockedDeviceState);
when(mockedDeviceContext.getDeviceInfo()).thenReturn(mockedDeviceInfo);
when(mockedDeviceContext.getDeviceFlowRegistry()).thenReturn(mockedFlowRegistry);
when(mockedFlowRegistry.retrieveDescriptor(Matchers.any(FlowRegistryKey.class))).thenReturn(mockedFlowDescriptor);
final InstanceIdentifier<FlowCapableNode> nodePath = mockedDeviceInfo.getNodeInstanceIdentifier().augmentation(FlowCapableNode.class);
final FlowCapableNodeBuilder flowNodeBuilder = new FlowCapableNodeBuilder();
flowNodeBuilder.setTable(Collections.<Table>emptyList());
final Optional<FlowCapableNode> flowNodeOpt = Optional.of(flowNodeBuilder.build());
final CheckedFuture<Optional<FlowCapableNode>, ReadFailedException> flowNodeFuture = Futures.immediateCheckedFuture(flowNodeOpt);
when(mockedReadOnlyTx.read(LogicalDatastoreType.OPERATIONAL, nodePath)).thenReturn(flowNodeFuture);
when(mockedDeviceContext.getReadTransaction()).thenReturn(mockedReadOnlyTx);
dummyRequestContext = new AbstractRequestContext<List<MultipartReply>>(DUMMY_XID) {
@Override
public void close() {
// NOOP
}
};
final ConvertorManager convertorManager = ConvertorManagerFactory.createDefaultManager();
multipartRequestOnTheFlyCallback = new MultiLayerFlowMultipartRequestOnTheFlyCallback<>(dummyRequestContext, String.class, mockedDeviceContext, dummyEventIdentifier, MultipartWriterProviderFactory.createDefaultProvider(mockedDeviceContext), convertorManager);
}
Aggregations