Search in sources :

Example 1 with UpdateTableInput

use of org.opendaylight.yang.gen.v1.urn.opendaylight.table.service.rev131026.UpdateTableInput in project openflowplugin by opendaylight.

the class TableForwarderTest method testUpdate.

@Test
public void testUpdate() throws Exception {
    Mockito.when(salTableService.updateTable(updateTableInputCpt.capture())).thenReturn(RpcResultBuilder.success(new UpdateTableOutputBuilder().setTransactionId(txId).build()).buildFuture());
    final TableFeatures tableFeaturesUpdate = new TableFeaturesBuilder(tableFeatures).setName("another-table").build();
    final Future<RpcResult<UpdateTableOutput>> updateResult = tableForwarder.update(tableFeaturesPath, tableFeatures, tableFeaturesUpdate, flowCapableNodePath);
    Mockito.verify(salTableService).updateTable(Matchers.<UpdateTableInput>any());
    Assert.assertTrue(updateResult.isDone());
    final RpcResult<UpdateTableOutput> updateTableResult = updateResult.get(2, TimeUnit.SECONDS);
    Assert.assertTrue(updateTableResult.isSuccessful());
    Assert.assertEquals(1, updateTableResult.getResult().getTransactionId().getValue().intValue());
    final UpdateTableInput updateTableInput = updateTableInputCpt.getValue();
    Assert.assertEquals(tablePath, updateTableInput.getTableRef().getValue());
    Assert.assertEquals(nodePath, updateTableInput.getNode().getValue());
    Assert.assertEquals(1, updateTableInput.getOriginalTable().getTableFeatures().size());
    Assert.assertEquals("test-table", updateTableInput.getOriginalTable().getTableFeatures().get(0).getName());
    Assert.assertEquals(1, updateTableInput.getUpdatedTable().getTableFeatures().size());
    Assert.assertEquals("another-table", updateTableInput.getUpdatedTable().getTableFeatures().get(0).getName());
}
Also used : UpdateTableOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.table.service.rev131026.UpdateTableOutput) TableFeatures(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.features.TableFeatures) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) TableFeaturesBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.features.TableFeaturesBuilder) UpdateTableInput(org.opendaylight.yang.gen.v1.urn.opendaylight.table.service.rev131026.UpdateTableInput) UpdateTableOutputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.table.service.rev131026.UpdateTableOutputBuilder) Test(org.junit.Test)

Example 2 with UpdateTableInput

use of org.opendaylight.yang.gen.v1.urn.opendaylight.table.service.rev131026.UpdateTableInput in project openflowplugin by opendaylight.

the class TableFeaturesListenerTest method updateFlowTest.

@Test
public void updateFlowTest() {
    TableKey tableKey = new TableKey((short) 2);
    TableFeaturesKey tableFeaturesKey = new TableFeaturesKey(tableKey.getId());
    addTable(tableKey, NODE_KEY);
    TableFeatures tableFeaturesData = new TableFeaturesBuilder().setKey(tableFeaturesKey).build();
    InstanceIdentifier<TableFeatures> tableFeaturesII = InstanceIdentifier.create(Nodes.class).child(Node.class, NODE_KEY).augmentation(FlowCapableNode.class).child(TableFeatures.class, tableFeaturesKey);
    WriteTransaction writeTx = getDataBroker().newWriteOnlyTransaction();
    writeTx.put(LogicalDatastoreType.CONFIGURATION, tableFeaturesII, tableFeaturesData);
    assertCommit(writeTx.submit());
    tableFeaturesData = new TableFeaturesBuilder().setKey(tableFeaturesKey).setName("dummy name").build();
    writeTx = getDataBroker().newWriteOnlyTransaction();
    writeTx.put(LogicalDatastoreType.CONFIGURATION, tableFeaturesII, tableFeaturesData);
    assertCommit(writeTx.submit());
    SalTableServiceMock salTableServiceMock = (SalTableServiceMock) forwardingRulesManager.getSalTableService();
    List<UpdateTableInput> updateTableInputs = salTableServiceMock.getUpdateTableInput();
    assertEquals(1, updateTableInputs.size());
    assertEquals("DOM-0", updateTableInputs.get(0).getTransactionUri().getValue());
}
Also used : WriteTransaction(org.opendaylight.controller.md.sal.binding.api.WriteTransaction) TableFeatures(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.features.TableFeatures) TableFeaturesKey(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.features.TableFeaturesKey) FlowCapableNode(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode) SalTableServiceMock(test.mock.util.SalTableServiceMock) TableFeaturesBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.features.TableFeaturesBuilder) UpdateTableInput(org.opendaylight.yang.gen.v1.urn.opendaylight.table.service.rev131026.UpdateTableInput) TableKey(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.TableKey) Nodes(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes) FRMTest(test.mock.util.FRMTest) Test(org.junit.Test)

Example 3 with UpdateTableInput

use of org.opendaylight.yang.gen.v1.urn.opendaylight.table.service.rev131026.UpdateTableInput in project openflowplugin by opendaylight.

the class SingleLayerTableMultipartServiceTest method buildRequest.

@Test
public void buildRequest() throws Exception {
    final UpdateTableInput input = new UpdateTableInputBuilder().setUpdatedTable(new UpdatedTableBuilder().setTableFeatures(Collections.singletonList(new TableFeaturesBuilder().setMaxEntries(MAX_ENTRIES).build())).build()).build();
    final OfHeader ofHeader = service.buildRequest(DUMMY_XID, input);
    assertEquals(MultipartRequest.class, ofHeader.getImplementedInterface());
    final MultipartRequestTableFeatures result = MultipartRequestTableFeatures.class.cast(MultipartRequest.class.cast(ofHeader).getMultipartRequestBody());
    assertEquals(MAX_ENTRIES, result.getTableFeatures().get(0).getMaxEntries().longValue());
}
Also used : OfHeader(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader) UpdateTableInput(org.opendaylight.yang.gen.v1.urn.opendaylight.table.service.rev131026.UpdateTableInput) UpdatedTableBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.table.service.rev131026.table.update.UpdatedTableBuilder) TableFeaturesBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.features.TableFeaturesBuilder) MultipartReplyTableFeaturesBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.multipart.reply.multipart.reply.body.MultipartReplyTableFeaturesBuilder) MultipartRequestTableFeatures(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.multipart.request.multipart.request.body.MultipartRequestTableFeatures) UpdateTableInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.table.service.rev131026.UpdateTableInputBuilder) Test(org.junit.Test)

Example 4 with UpdateTableInput

use of org.opendaylight.yang.gen.v1.urn.opendaylight.table.service.rev131026.UpdateTableInput in project openflowplugin by opendaylight.

the class SingleLayerTableMultipartServiceTest method handleAndReply.

@Test
public void handleAndReply() throws Exception {
    mockSuccessfulFuture(Collections.singletonList(new MultipartReplyBuilder().setXid(XID).setMultipartReplyBody(new MultipartReplyTableFeaturesBuilder().setTableFeatures(Collections.singletonList(new TableFeaturesBuilder().setMaxEntries(MAX_ENTRIES).build())).build()).build()));
    final UpdateTableInput input = new UpdateTableInputBuilder().setUpdatedTable(new UpdatedTableBuilder().setTableFeatures(Collections.singletonList(new TableFeaturesBuilder().setMaxEntries(MAX_ENTRIES).build())).build()).build();
    final Future<RpcResult<UpdateTableOutput>> rpcResultFuture = service.handleAndReply(input);
    final RpcResult<UpdateTableOutput> result = rpcResultFuture.get();
    assertTrue(result.isSuccessful());
    assertEquals(XID, result.getResult().getTransactionId().getValue().longValue());
}
Also used : UpdateTableOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.table.service.rev131026.UpdateTableOutput) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) MultipartReplyBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.multipart.types.rev170112.MultipartReplyBuilder) TableFeaturesBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.features.TableFeaturesBuilder) MultipartReplyTableFeaturesBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.multipart.reply.multipart.reply.body.MultipartReplyTableFeaturesBuilder) UpdateTableInput(org.opendaylight.yang.gen.v1.urn.opendaylight.table.service.rev131026.UpdateTableInput) UpdatedTableBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.table.service.rev131026.table.update.UpdatedTableBuilder) MultipartReplyTableFeaturesBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.multipart.reply.multipart.reply.body.MultipartReplyTableFeaturesBuilder) UpdateTableInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.table.service.rev131026.UpdateTableInputBuilder) Test(org.junit.Test)

Example 5 with UpdateTableInput

use of org.opendaylight.yang.gen.v1.urn.opendaylight.table.service.rev131026.UpdateTableInput in project openflowplugin by opendaylight.

the class MultiLayerTableMultipartService method handleAndReply.

@Override
public Future<RpcResult<UpdateTableOutput>> handleAndReply(UpdateTableInput input) {
    final ListenableFuture<RpcResult<List<MultipartReply>>> multipartFuture = handleServiceCall(input);
    final SettableFuture<RpcResult<UpdateTableOutput>> finalFuture = SettableFuture.create();
    class CallBackImpl implements FutureCallback<RpcResult<List<MultipartReply>>> {

        @Override
        @SuppressWarnings("checkstyle:IllegalCatch")
        public void onSuccess(@Nonnull final RpcResult<List<MultipartReply>> result) {
            if (result.isSuccessful()) {
                final List<MultipartReply> multipartReplies = result.getResult();
                if (multipartReplies.isEmpty()) {
                    LOG.debug("Multipart reply to table features request shouldn't be empty list.");
                    finalFuture.set(RpcResultBuilder.<UpdateTableOutput>failed().withError(ErrorType.RPC, "Multipart reply list is empty.").build());
                } else {
                    final Long xid = multipartReplies.get(0).getXid();
                    LOG.debug("OnSuccess, rpc result successful," + " multipart response for rpc update-table with xid {} obtained.", xid);
                    final UpdateTableOutputBuilder updateTableOutputBuilder = new UpdateTableOutputBuilder();
                    updateTableOutputBuilder.setTransactionId(new TransactionId(BigInteger.valueOf(xid)));
                    finalFuture.set(RpcResultBuilder.success(updateTableOutputBuilder.build()).build());
                    try {
                        storeStatistics(convertToSalTableFeatures(multipartReplies));
                    } catch (Exception e) {
                        LOG.warn("Not able to write to operational datastore: {}", e.getMessage());
                    }
                }
            } else {
                LOG.debug("OnSuccess, rpc result unsuccessful," + " multipart response for rpc update-table was unsuccessful.");
                finalFuture.set(RpcResultBuilder.<UpdateTableOutput>failed().withRpcErrors(result.getErrors()).build());
            }
        }

        @Override
        public void onFailure(final Throwable throwable) {
            LOG.error("Failure multipart response for table features request. Exception: {}", throwable);
            finalFuture.set(RpcResultBuilder.<UpdateTableOutput>failed().withError(ErrorType.RPC, "Future error", throwable).build());
        }
    }
    Futures.addCallback(multipartFuture, new CallBackImpl(), MoreExecutors.directExecutor());
    return finalFuture;
}
Also used : Nonnull(javax.annotation.Nonnull) MultipartReply(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReply) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) ServiceException(org.opendaylight.openflowplugin.impl.services.util.ServiceException) TransactionId(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.transaction.rev150304.TransactionId) ArrayList(java.util.ArrayList) List(java.util.List) UpdateTableOutputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.table.service.rev131026.UpdateTableOutputBuilder) FutureCallback(com.google.common.util.concurrent.FutureCallback)

Aggregations

Test (org.junit.Test)4 UpdateTableInput (org.opendaylight.yang.gen.v1.urn.opendaylight.table.service.rev131026.UpdateTableInput)4 TableFeaturesBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.features.TableFeaturesBuilder)4 UpdateTableInputBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.table.service.rev131026.UpdateTableInputBuilder)3 UpdatedTableBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.table.service.rev131026.table.update.UpdatedTableBuilder)3 RpcResult (org.opendaylight.yangtools.yang.common.RpcResult)3 UpdateTableOutput (org.opendaylight.yang.gen.v1.urn.opendaylight.table.service.rev131026.UpdateTableOutput)2 UpdateTableOutputBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.table.service.rev131026.UpdateTableOutputBuilder)2 MultipartReplyTableFeaturesBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.multipart.reply.multipart.reply.body.MultipartReplyTableFeaturesBuilder)2 TableFeatures (org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.features.TableFeatures)2 FutureCallback (com.google.common.util.concurrent.FutureCallback)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Nonnull (javax.annotation.Nonnull)1 WriteTransaction (org.opendaylight.controller.md.sal.binding.api.WriteTransaction)1 ServiceException (org.opendaylight.openflowplugin.impl.services.util.ServiceException)1 FlowCapableNode (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode)1 TableKey (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.TableKey)1 TransactionId (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.transaction.rev150304.TransactionId)1 Nodes (org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes)1