Example usage for com.google.common.util.concurrent JdkFutureAdapters listenInPoolThread

List of usage examples for com.google.common.util.concurrent JdkFutureAdapters listenInPoolThread

Introduction

In this page you can find the example usage for com.google.common.util.concurrent JdkFutureAdapters listenInPoolThread.

Prototype

public static <V> ListenableFuture<V> listenInPoolThread(Future<V> future) 

Source Link

Document

Assigns a thread to the given Future to provide ListenableFuture functionality.

Usage

From source file:org.opendaylight.openflowplugin.openflow.md.core.sal.OFRpcTaskFactory.java

/**
 * @param taskContext task context//w w  w . ja  v a 2  s  . c om
 * @param input get aggregate flow statistics from flow table for all flow input
 * @param cookie switch connection distinguisher cookie value
 * @return task get aggregate flow stats from flow table for all flow task
 */
public static OFRpcTask<GetAggregateFlowStatisticsFromFlowTableForAllFlowsInput, RpcResult<GetAggregateFlowStatisticsFromFlowTableForAllFlowsOutput>> createGetAggregateFlowStatisticsFromFlowTableForAllFlowsTask(
        final OFRpcTaskContext taskContext, final GetAggregateFlowStatisticsFromFlowTableForAllFlowsInput input,
        SwitchConnectionDistinguisher cookie) {
    class OFRpcTaskImpl extends
            OFRpcTask<GetAggregateFlowStatisticsFromFlowTableForAllFlowsInput, RpcResult<GetAggregateFlowStatisticsFromFlowTableForAllFlowsOutput>> {

        public OFRpcTaskImpl(OFRpcTaskContext taskContext, SwitchConnectionDistinguisher cookie,
                GetAggregateFlowStatisticsFromFlowTableForAllFlowsInput input) {
            super(taskContext, cookie, input);
        }

        @Override
        public ListenableFuture<RpcResult<GetAggregateFlowStatisticsFromFlowTableForAllFlowsOutput>> call()
                throws Exception {
            final SettableFuture<RpcResult<GetAggregateFlowStatisticsFromFlowTableForAllFlowsOutput>> result = SettableFuture
                    .create();

            final Long xid = taskContext.getSession().getNextXid();

            // Create multipart request body for fetch all the group stats
            MultipartRequestAggregateCaseBuilder multipartRequestAggregateCaseBuilder = new MultipartRequestAggregateCaseBuilder();
            MultipartRequestAggregateBuilder mprAggregateRequestBuilder = new MultipartRequestAggregateBuilder();
            mprAggregateRequestBuilder.setTableId(input.getTableId().getValue());
            mprAggregateRequestBuilder.setOutPort(OFConstants.OFPP_ANY);
            mprAggregateRequestBuilder.setOutGroup(OFConstants.OFPG_ANY);
            mprAggregateRequestBuilder.setCookie(OFConstants.DEFAULT_COOKIE);
            mprAggregateRequestBuilder.setCookieMask(OFConstants.DEFAULT_COOKIE_MASK);

            FlowCreatorUtil.setWildcardedFlowMatch(taskContext.getSession().getPrimaryConductor().getVersion(),
                    mprAggregateRequestBuilder);

            // Set request body to main multipart request
            multipartRequestAggregateCaseBuilder
                    .setMultipartRequestAggregate(mprAggregateRequestBuilder.build());
            MultipartRequestInputBuilder mprInput = createMultipartHeader(MultipartType.OFPMPAGGREGATE,
                    taskContext, xid);
            mprInput.setMultipartRequestBody(multipartRequestAggregateCaseBuilder.build());
            Future<RpcResult<Void>> resultFromOFLib = getMessageService().multipartRequest(mprInput.build(),
                    getCookie());
            ListenableFuture<RpcResult<Void>> resultLib = JdkFutureAdapters.listenInPoolThread(resultFromOFLib);

            Futures.addCallback(resultLib,
                    new ResultCallback<GetAggregateFlowStatisticsFromFlowTableForAllFlowsOutput>(result) {
                        @Override
                        public GetAggregateFlowStatisticsFromFlowTableForAllFlowsOutput createResult() {
                            GetAggregateFlowStatisticsFromFlowTableForAllFlowsOutputBuilder flowStatsFromFlowTableBuilder = new GetAggregateFlowStatisticsFromFlowTableForAllFlowsOutputBuilder()
                                    .setTransactionId(new TransactionId(BigInteger.valueOf(xid)));
                            return flowStatsFromFlowTableBuilder.build();
                        }
                    });
            return result;
        }
    }

    return new OFRpcTaskImpl(taskContext, cookie, input);
}

From source file:org.opendaylight.openflowplugin.openflow.md.core.sal.OFRpcTaskFactory.java

/**
 * @param taskContext task context// www. j  ava  2 s.  c  om
 * @param input aggregate flow statistics input
 * @param cookie switch connection distinguisher cookie value
 * @return task task to fetch the statistics
 */
public static OFRpcTask<GetAggregateFlowStatisticsFromFlowTableForGivenMatchInput, RpcResult<GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutput>> createGetAggregateFlowStatisticsFromFlowTableForGivenMatchTask(
        final OFRpcTaskContext taskContext,
        final GetAggregateFlowStatisticsFromFlowTableForGivenMatchInput input,
        SwitchConnectionDistinguisher cookie) {
    class OFRpcTaskImpl extends
            OFRpcTask<GetAggregateFlowStatisticsFromFlowTableForGivenMatchInput, RpcResult<GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutput>> {

        public OFRpcTaskImpl(OFRpcTaskContext taskContext, SwitchConnectionDistinguisher cookie,
                GetAggregateFlowStatisticsFromFlowTableForGivenMatchInput input) {
            super(taskContext, cookie, input);
        }

        @Override
        public ListenableFuture<RpcResult<GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutput>> call()
                throws Exception {
            final SettableFuture<RpcResult<GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutput>> result = SettableFuture
                    .create();

            final Long xid = taskContext.getSession().getNextXid();

            MultipartRequestAggregateCaseBuilder multipartRequestAggregateCaseBuilder = new MultipartRequestAggregateCaseBuilder();
            MultipartRequestAggregateBuilder mprAggregateRequestBuilder = new MultipartRequestAggregateBuilder();
            mprAggregateRequestBuilder.setTableId(input.getTableId());
            mprAggregateRequestBuilder.setOutPort(input.getOutPort().longValue());
            // TODO: repeating code
            if (taskContext.getSession().getPrimaryConductor().getVersion() == OFConstants.OFP_VERSION_1_3) {
                mprAggregateRequestBuilder.setCookie(input.getCookie().getValue());
                mprAggregateRequestBuilder.setCookieMask(input.getCookieMask().getValue());
                mprAggregateRequestBuilder.setOutGroup(input.getOutGroup());
            } else {
                mprAggregateRequestBuilder.setOutGroup(OFConstants.OFPG_ANY);
                mprAggregateRequestBuilder.setCookie(OFConstants.DEFAULT_COOKIE);
                mprAggregateRequestBuilder.setCookieMask(OFConstants.DEFAULT_COOKIE_MASK);
            }

            MatchReactor.getInstance().convert(input.getMatch(),
                    taskContext.getSession().getPrimaryConductor().getVersion(), mprAggregateRequestBuilder,
                    taskContext.getSession().getFeatures().getDatapathId());

            FlowCreatorUtil.setWildcardedFlowMatch(taskContext.getSession().getPrimaryConductor().getVersion(),
                    mprAggregateRequestBuilder);

            // Set request body to main multipart request
            multipartRequestAggregateCaseBuilder
                    .setMultipartRequestAggregate(mprAggregateRequestBuilder.build());
            MultipartRequestInputBuilder mprInput = createMultipartHeader(MultipartType.OFPMPAGGREGATE,
                    taskContext, xid);
            mprInput.setMultipartRequestBody(multipartRequestAggregateCaseBuilder.build());
            Future<RpcResult<Void>> resultFromOFLib = getMessageService().multipartRequest(mprInput.build(),
                    getCookie());
            ListenableFuture<RpcResult<Void>> resultLib = JdkFutureAdapters.listenInPoolThread(resultFromOFLib);

            Futures.addCallback(resultLib,
                    new ResultCallback<GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutput>(result) {
                        @Override
                        public GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutput createResult() {
                            GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutputBuilder aggregFlowStatsFromFlowTableBuilder = new GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutputBuilder()
                                    .setTransactionId(new TransactionId(BigInteger.valueOf(xid)));
                            return aggregFlowStatsFromFlowTableBuilder.build();
                        }
                    });
            return result;
        }
    }

    return new OFRpcTaskImpl(taskContext, cookie, input);
}

From source file:org.opendaylight.openflowplugin.openflow.md.core.sal.OFRpcTaskFactory.java

/**
 * @param taskContext task context/*from  www .  j a va 2 s  .c  om*/
 * @param input flow table statistics input
 * @param cookie switch connection distinguisher cookie value
 * @return task task to fetch table statistics
 */
public static OFRpcTask<GetFlowTablesStatisticsInput, RpcResult<GetFlowTablesStatisticsOutput>> createGetFlowTablesStatisticsTask(
        final OFRpcTaskContext taskContext, final GetFlowTablesStatisticsInput input,
        SwitchConnectionDistinguisher cookie) {

    class OFRpcTaskImpl
            extends OFRpcTask<GetFlowTablesStatisticsInput, RpcResult<GetFlowTablesStatisticsOutput>> {

        public OFRpcTaskImpl(OFRpcTaskContext taskContext, SwitchConnectionDistinguisher cookie,
                GetFlowTablesStatisticsInput input) {
            super(taskContext, cookie, input);
        }

        @Override
        public ListenableFuture<RpcResult<GetFlowTablesStatisticsOutput>> call() throws Exception {
            final SettableFuture<RpcResult<GetFlowTablesStatisticsOutput>> result = SettableFuture.create();

            final Long xid = taskContext.getSession().getNextXid();

            // Create multipart request body for fetch all the group stats
            MultipartRequestTableCaseBuilder multipartRequestTableCaseBuilder = new MultipartRequestTableCaseBuilder();
            MultipartRequestTableBuilder multipartRequestTableBuilder = new MultipartRequestTableBuilder();
            multipartRequestTableBuilder.setEmpty(true);
            multipartRequestTableCaseBuilder.setMultipartRequestTable(multipartRequestTableBuilder.build());

            // Set request body to main multipart request
            MultipartRequestInputBuilder mprInput = createMultipartHeader(MultipartType.OFPMPTABLE, taskContext,
                    xid);
            mprInput.setMultipartRequestBody(multipartRequestTableCaseBuilder.build());
            Future<RpcResult<Void>> resultFromOFLib = getMessageService().multipartRequest(mprInput.build(),
                    getCookie());
            ListenableFuture<RpcResult<Void>> resultLib = JdkFutureAdapters.listenInPoolThread(resultFromOFLib);

            Futures.addCallback(resultLib, new ResultCallback<GetFlowTablesStatisticsOutput>(result) {
                @Override
                public GetFlowTablesStatisticsOutput createResult() {
                    GetFlowTablesStatisticsOutputBuilder flowTableStatsBuilder = new GetFlowTablesStatisticsOutputBuilder()
                            .setTransactionId(new TransactionId(BigInteger.valueOf(xid)));
                    return flowTableStatsBuilder.build();
                }
            });
            return result;
        }
    }

    return new OFRpcTaskImpl(taskContext, cookie, input);
}

From source file:org.opendaylight.vpnservice.natservice.internal.ExternalRoutersListener.java

private void clrRtsFromBgpAndDelFibTs(final BigInteger dpnId, long routerId, String extIp,
        final String vpnName) {
    //Inform BGP about the route removal
    String rd = NatUtil.getVpnRd(dataBroker, vpnName);
    NatUtil.removePrefixFromBGP(bgpManager, rd, extIp, LOG);

    LOG.debug("Removing fib entry for externalIp {} in routerId {}", extIp, routerId);
    //Get IPMaps from the DB for the router ID
    List<IpMap> dbIpMaps = NaptManager.getIpMapList(dataBroker, routerId);
    if (dbIpMaps == null || dbIpMaps.isEmpty()) {
        LOG.error("NAT Service : IPMaps not found for router {}", routerId);
        return;//from  ww  w  . j  a  v  a2 s  .c  om
    }

    long tempLabel = NatConstants.INVALID_ID;
    for (IpMap dbIpMap : dbIpMaps) {
        String dbExternalIp = dbIpMap.getExternalIp();
        LOG.debug("Retrieved dbExternalIp {} for router id {}", dbExternalIp, routerId);
        //Select the IPMap, whose external IP is the IP for which FIB is installed
        if (extIp.equals(dbExternalIp)) {
            tempLabel = dbIpMap.getLabel();
            LOG.debug("Retrieved label {} for dbExternalIp {} with router id {}", tempLabel, dbExternalIp,
                    routerId);
            break;
        }
    }
    if (tempLabel < 0 || tempLabel == NatConstants.INVALID_ID) {
        LOG.error("NAT Service : Label not found for externalIp {} with router id {}", extIp, routerId);
        return;
    }

    final long label = tempLabel;
    final String externalIp = extIp;

    RemoveFibEntryInput input = new RemoveFibEntryInputBuilder().setVpnName(vpnName).setSourceDpid(dpnId)
            .setIpAddress(externalIp).setServiceId(label).build();
    Future<RpcResult<Void>> future = fibService.removeFibEntry(input);

    ListenableFuture<RpcResult<Void>> labelFuture = Futures.transform(
            JdkFutureAdapters.listenInPoolThread(future),
            new AsyncFunction<RpcResult<Void>, RpcResult<Void>>() {

                @Override
                public ListenableFuture<RpcResult<Void>> apply(RpcResult<Void> result) throws Exception {
                    //Release label
                    if (result.isSuccessful()) {
                        removeTunnelTableEntry(dpnId, label);
                        removeLFibTableEntry(dpnId, label);
                        RemoveVpnLabelInput labelInput = new RemoveVpnLabelInputBuilder().setVpnName(vpnName)
                                .setIpPrefix(externalIp).build();
                        Future<RpcResult<Void>> labelFuture = vpnService.removeVpnLabel(labelInput);
                        return JdkFutureAdapters.listenInPoolThread(labelFuture);
                    } else {
                        String errMsg = String.format(
                                "RPC call to remove custom FIB entries on dpn %s for prefix %s Failed - %s",
                                dpnId, externalIp, result.getErrors());
                        LOG.error(errMsg);
                        return Futures.immediateFailedFuture(new RuntimeException(errMsg));
                    }
                }

            });

    Futures.addCallback(labelFuture, new FutureCallback<RpcResult<Void>>() {

        @Override
        public void onFailure(Throwable error) {
            LOG.error("NAT Service : Error in removing the label or custom fib entries", error);
        }

        @Override
        public void onSuccess(RpcResult<Void> result) {
            if (result.isSuccessful()) {
                LOG.debug("NAT Service : Successfully removed the label for the prefix {} from VPN {}",
                        externalIp, vpnName);
            } else {
                LOG.error("NAT Service : Error in removing the label for prefix {} from VPN {}, {}", externalIp,
                        vpnName, result.getErrors());
            }
        }
    });
}

From source file:org.opendaylight.openflowplugin.openflow.md.core.sal.OFRpcTaskFactory.java

/**
 * @param taskContext task context//from  ww  w.  jav  a 2s. c  o  m
 * @param input queue statistics input
 * @param cookie switch connection distinguisher cookie value
 * @return task task to fetch all queue statistics
 */
public static OFRpcTask<GetAllQueuesStatisticsFromAllPortsInput, RpcResult<GetAllQueuesStatisticsFromAllPortsOutput>> createGetAllQueuesStatisticsFromAllPortsTask(
        final OFRpcTaskContext taskContext, final GetAllQueuesStatisticsFromAllPortsInput input,
        SwitchConnectionDistinguisher cookie) {

    class OFRpcTaskImpl extends
            OFRpcTask<GetAllQueuesStatisticsFromAllPortsInput, RpcResult<GetAllQueuesStatisticsFromAllPortsOutput>> {

        public OFRpcTaskImpl(OFRpcTaskContext taskContext, SwitchConnectionDistinguisher cookie,
                GetAllQueuesStatisticsFromAllPortsInput input) {
            super(taskContext, cookie, input);
        }

        @Override
        public ListenableFuture<RpcResult<GetAllQueuesStatisticsFromAllPortsOutput>> call() throws Exception {
            final SettableFuture<RpcResult<GetAllQueuesStatisticsFromAllPortsOutput>> result = SettableFuture
                    .create();

            final Long xid = taskContext.getSession().getNextXid();

            MultipartRequestQueueCaseBuilder caseBuilder = new MultipartRequestQueueCaseBuilder();
            MultipartRequestQueueBuilder mprQueueBuilder = new MultipartRequestQueueBuilder();
            // Select all ports
            mprQueueBuilder.setPortNo(OFConstants.OFPP_ANY);
            // Select all the queues
            mprQueueBuilder.setQueueId(OFConstants.OFPQ_ALL);
            caseBuilder.setMultipartRequestQueue(mprQueueBuilder.build());

            // Set request body to main multipart request
            MultipartRequestInputBuilder mprInput = createMultipartHeader(MultipartType.OFPMPQUEUE, taskContext,
                    xid);
            mprInput.setMultipartRequestBody(caseBuilder.build());
            Future<RpcResult<Void>> resultFromOFLib = getMessageService().multipartRequest(mprInput.build(),
                    getCookie());
            ListenableFuture<RpcResult<Void>> resultLib = JdkFutureAdapters.listenInPoolThread(resultFromOFLib);

            Futures.addCallback(resultLib,
                    new ResultCallback<GetAllQueuesStatisticsFromAllPortsOutput>(result) {
                        @Override
                        public GetAllQueuesStatisticsFromAllPortsOutput createResult() {
                            GetAllQueuesStatisticsFromAllPortsOutputBuilder allQueueStatsBuilder = new GetAllQueuesStatisticsFromAllPortsOutputBuilder()
                                    .setTransactionId(new TransactionId(BigInteger.valueOf(xid)));
                            return allQueueStatsBuilder.build();
                        }
                    });
            return result;
        }
    }

    return new OFRpcTaskImpl(taskContext, cookie, input);
}

From source file:org.opendaylight.openflowplugin.openflow.md.core.sal.OFRpcTaskFactory.java

/**
 * @param taskContext task context//from  ww  w.jav  a 2s. co  m
 * @param input queue statist from specific port input
 * @param cookie switch connection distinguisher cookie value
 * @return task task to get queue statistics from specific port
 */
public static OFRpcTask<GetAllQueuesStatisticsFromGivenPortInput, RpcResult<GetAllQueuesStatisticsFromGivenPortOutput>> createGetAllQueuesStatisticsFromGivenPortTask(
        final OFRpcTaskContext taskContext, final GetAllQueuesStatisticsFromGivenPortInput input,
        SwitchConnectionDistinguisher cookie) {

    class OFRpcTaskImpl extends
            OFRpcTask<GetAllQueuesStatisticsFromGivenPortInput, RpcResult<GetAllQueuesStatisticsFromGivenPortOutput>> {

        public OFRpcTaskImpl(OFRpcTaskContext taskContext, SwitchConnectionDistinguisher cookie,
                GetAllQueuesStatisticsFromGivenPortInput input) {
            super(taskContext, cookie, input);
        }

        @Override
        public ListenableFuture<RpcResult<GetAllQueuesStatisticsFromGivenPortOutput>> call() throws Exception {
            final SettableFuture<RpcResult<GetAllQueuesStatisticsFromGivenPortOutput>> result = SettableFuture
                    .create();

            final Long xid = taskContext.getSession().getNextXid();

            MultipartRequestQueueCaseBuilder caseBuilder = new MultipartRequestQueueCaseBuilder();
            MultipartRequestQueueBuilder mprQueueBuilder = new MultipartRequestQueueBuilder();
            // Select all queues
            mprQueueBuilder.setQueueId(OFConstants.OFPQ_ALL);
            // Select specific port
            mprQueueBuilder.setPortNo(InventoryDataServiceUtil.portNumberfromNodeConnectorId(
                    OpenflowVersion.get(taskContext.getSession().getFeatures().getVersion()),
                    input.getNodeConnectorId()));
            caseBuilder.setMultipartRequestQueue(mprQueueBuilder.build());

            // Set request body to main multipart request
            MultipartRequestInputBuilder mprInput = createMultipartHeader(MultipartType.OFPMPQUEUE, taskContext,
                    xid);
            mprInput.setMultipartRequestBody(caseBuilder.build());
            Future<RpcResult<Void>> resultFromOFLib = getMessageService().multipartRequest(mprInput.build(),
                    getCookie());
            ListenableFuture<RpcResult<Void>> resultLib = JdkFutureAdapters.listenInPoolThread(resultFromOFLib);

            Futures.addCallback(resultLib,
                    new ResultCallback<GetAllQueuesStatisticsFromGivenPortOutput>(result) {
                        @Override
                        public GetAllQueuesStatisticsFromGivenPortOutput createResult() {
                            GetAllQueuesStatisticsFromGivenPortOutputBuilder allQueueStatsBuilder = new GetAllQueuesStatisticsFromGivenPortOutputBuilder()
                                    .setTransactionId(new TransactionId(BigInteger.valueOf(xid)));
                            return allQueueStatsBuilder.build();
                        }
                    });
            return result;
        }
    }

    return new OFRpcTaskImpl(taskContext, cookie, input);
}

From source file:org.opendaylight.openflowplugin.openflow.md.core.sal.OFRpcTaskFactory.java

/**
 * @param taskContext task context//www.  j a v a2 s.  c  o  m
 * @param input queue statistics from given port
 * @param cookie switch connection distinguisher cookie value
 * @return task task to get queue statistics from given port
 */
public static OFRpcTask<GetQueueStatisticsFromGivenPortInput, RpcResult<GetQueueStatisticsFromGivenPortOutput>> createGetQueueStatisticsFromGivenPortTask(
        final OFRpcTaskContext taskContext, final GetQueueStatisticsFromGivenPortInput input,
        SwitchConnectionDistinguisher cookie) {

    class OFRpcTaskImpl extends
            OFRpcTask<GetQueueStatisticsFromGivenPortInput, RpcResult<GetQueueStatisticsFromGivenPortOutput>> {

        public OFRpcTaskImpl(OFRpcTaskContext taskContext, SwitchConnectionDistinguisher cookie,
                GetQueueStatisticsFromGivenPortInput input) {
            super(taskContext, cookie, input);
        }

        @Override
        public ListenableFuture<RpcResult<GetQueueStatisticsFromGivenPortOutput>> call() throws Exception {
            final SettableFuture<RpcResult<GetQueueStatisticsFromGivenPortOutput>> result = SettableFuture
                    .create();

            final Long xid = taskContext.getSession().getNextXid();

            MultipartRequestQueueCaseBuilder caseBuilder = new MultipartRequestQueueCaseBuilder();
            MultipartRequestQueueBuilder mprQueueBuilder = new MultipartRequestQueueBuilder();
            // Select specific queue
            mprQueueBuilder.setQueueId(input.getQueueId().getValue());
            // Select specific port
            mprQueueBuilder.setPortNo(InventoryDataServiceUtil.portNumberfromNodeConnectorId(
                    OpenflowVersion.get(taskContext.getSession().getFeatures().getVersion()),
                    input.getNodeConnectorId()));
            caseBuilder.setMultipartRequestQueue(mprQueueBuilder.build());

            // Set request body to main multipart request
            MultipartRequestInputBuilder mprInput = createMultipartHeader(MultipartType.OFPMPQUEUE, taskContext,
                    xid);
            mprInput.setMultipartRequestBody(caseBuilder.build());
            Future<RpcResult<Void>> resultFromOFLib = getMessageService().multipartRequest(mprInput.build(),
                    getCookie());
            ListenableFuture<RpcResult<Void>> resultLib = JdkFutureAdapters.listenInPoolThread(resultFromOFLib);

            Futures.addCallback(resultLib, new ResultCallback<GetQueueStatisticsFromGivenPortOutput>(result) {
                @Override
                public GetQueueStatisticsFromGivenPortOutput createResult() {
                    GetQueueStatisticsFromGivenPortOutputBuilder queueStatsFromPortBuilder = new GetQueueStatisticsFromGivenPortOutputBuilder()
                            .setTransactionId(new TransactionId(BigInteger.valueOf(xid)));
                    return queueStatsFromPortBuilder.build();
                }
            });
            return result;
        }
    }

    return new OFRpcTaskImpl(taskContext, cookie, input);
}

From source file:org.opendaylight.netvirt.natservice.internal.ExternalRoutersListener.java

protected void delFibTsAndReverseTraffic(final BigInteger dpnId, long routerId, String extIp,
        final String vpnName, long tempLabel) {
    LOG.debug("NAT Service : Removing fib entry for externalIp {} in routerId {}", extIp, routerId);
    String routerName = NatUtil.getRouterName(dataBroker, routerId);
    if (routerName == null) {
        LOG.error("NAT Service : Could not retrieve Router Name from Router ID {} ", routerId);
        return;//from www .  j  a  v  a2s.c o  m
    }
    ProviderTypes extNwProvType = NatEvpnUtil.getExtNwProvTypeFromRouterName(dataBroker, routerName);
    if (extNwProvType == null) {
        return;
    }
    /*  Remove the flow table19->44 and table36->44 entries for SNAT reverse traffic flow if the
     * external network provided type is VxLAN
     */
    if (extNwProvType == ProviderTypes.VXLAN) {
        evpnSnatFlowProgrammer.evpnDelFibTsAndReverseTraffic(dpnId, routerId, extIp, vpnName);
        return;
    }
    if (tempLabel < 0 || tempLabel == NatConstants.INVALID_ID) {
        LOG.error("NAT Service : Label not found for externalIp {} with router id {}", extIp, routerId);
        return;
    }

    final long label = tempLabel;
    final String externalIp = extIp;

    RemoveFibEntryInput input = new RemoveFibEntryInputBuilder().setVpnName(vpnName).setSourceDpid(dpnId)
            .setIpAddress(externalIp).setServiceId(label).build();
    Future<RpcResult<Void>> future = fibService.removeFibEntry(input);

    ListenableFuture<RpcResult<Void>> labelFuture = Futures.transform(
            JdkFutureAdapters.listenInPoolThread(future),
            (AsyncFunction<RpcResult<Void>, RpcResult<Void>>) result -> {
                //Release label
                if (result.isSuccessful()) {
                    removeTunnelTableEntry(dpnId, label);
                    removeLFibTableEntry(dpnId, label);
                    NatUtil.removePreDnatToSnatTableEntry(mdsalManager, dpnId);
                    RemoveVpnLabelInput labelInput = new RemoveVpnLabelInputBuilder().setVpnName(vpnName)
                            .setIpPrefix(externalIp).build();
                    Future<RpcResult<Void>> labelFuture1 = vpnService.removeVpnLabel(labelInput);
                    return JdkFutureAdapters.listenInPoolThread(labelFuture1);
                } else {
                    String errMsg = String.format(
                            "RPC call to remove custom FIB entries on dpn %s for prefix %s " + "Failed - %s",
                            dpnId, externalIp, result.getErrors());
                    LOG.error(errMsg);
                    return Futures.immediateFailedFuture(new RuntimeException(errMsg));
                }
            });

    Futures.addCallback(labelFuture, new FutureCallback<RpcResult<Void>>() {

        @Override
        public void onFailure(Throwable error) {
            LOG.error("NAT Service : Error in removing the label or custom fib entries", error);
        }

        @Override
        public void onSuccess(RpcResult<Void> result) {
            if (result.isSuccessful()) {
                LOG.debug("NAT Service : Successfully removed the label for the prefix {} from VPN {}",
                        externalIp, vpnName);
            } else {
                LOG.error("NAT Service : Error in removing the label for prefix {} from VPN {}, {}", externalIp,
                        vpnName, result.getErrors());
            }
        }
    });
}

From source file:org.opendaylight.openflowplugin.openflow.md.core.sal.OFRpcTaskFactory.java

/**
 * @param taskContext task context/*w  w  w  .j av  a  2  s  . co m*/
 * @param input update port input
 * @param cookie switch connection distinguisher cookie value
 * @return task task to update port
 */
public static OFRpcTask<UpdatePortInput, RpcResult<UpdatePortOutput>> createUpdatePortTask(
        final OFRpcTaskContext taskContext, final UpdatePortInput input,
        final SwitchConnectionDistinguisher cookie) {

    class OFRpcTaskImpl extends OFRpcTask<UpdatePortInput, RpcResult<UpdatePortOutput>> {

        public OFRpcTaskImpl(OFRpcTaskContext taskContext, SwitchConnectionDistinguisher cookie,
                UpdatePortInput input) {
            super(taskContext, cookie, input);
        }

        @Override
        public ListenableFuture<RpcResult<UpdatePortOutput>> call() {
            ListenableFuture<RpcResult<UpdatePortOutput>> result = SettableFuture.create();
            final Long xid = taskContext.getSession().getNextXid();
            Port inputPort = input.getUpdatedPort().getPort().getPort().get(0);

            PortModInput ofPortModInput = PortConvertor.toPortModInput(inputPort,
                    taskContext.getSession().getPrimaryConductor().getVersion());

            PortModInputBuilder mdInput = new PortModInputBuilder(ofPortModInput);
            mdInput.setXid(xid);

            Future<RpcResult<UpdatePortOutput>> resultFromOFLib = getMessageService().portMod(mdInput.build(),
                    cookie);
            result = JdkFutureAdapters.listenInPoolThread(resultFromOFLib);

            return result;
        }
    }

    return new OFRpcTaskImpl(taskContext, cookie, input);
}

From source file:org.opendaylight.openflowplugin.openflow.md.core.sal.OFRpcTaskFactory.java

/**
 * @param taskContext task context//from w ww .j  ava2 s  .  com
 * @param input update table input
 * @param cookie switch connection distinguisher cookie value
 * @return task task to udpate table input
 */
public static OFRpcTask<UpdateTableInput, RpcResult<UpdateTableOutput>> createUpdateTableTask(
        final OFRpcTaskContext taskContext, final UpdateTableInput input,
        final SwitchConnectionDistinguisher cookie) {

    class OFRpcTaskImpl extends OFRpcTask<UpdateTableInput, RpcResult<UpdateTableOutput>> {

        public OFRpcTaskImpl(OFRpcTaskContext taskContext, SwitchConnectionDistinguisher cookie,
                UpdateTableInput input) {
            super(taskContext, cookie, input);
        }

        @Override
        public ListenableFuture<RpcResult<UpdateTableOutput>> call() {
            final SettableFuture<RpcResult<UpdateTableOutput>> result = SettableFuture.create();

            final Long xid = taskContext.getSession().getNextXid();

            MultipartRequestTableFeaturesCaseBuilder caseBuilder = new MultipartRequestTableFeaturesCaseBuilder();
            MultipartRequestTableFeaturesBuilder requestBuilder = new MultipartRequestTableFeaturesBuilder();
            List<TableFeatures> ofTableFeatureList = TableFeaturesConvertor
                    .toTableFeaturesRequest(input.getUpdatedTable());
            requestBuilder.setTableFeatures(ofTableFeatureList);
            caseBuilder.setMultipartRequestTableFeatures(requestBuilder.build());

            // Set request body to main multipart request
            MultipartRequestInputBuilder mprInput = createMultipartHeader(MultipartType.OFPMPTABLEFEATURES,
                    taskContext, xid);
            mprInput.setMultipartRequestBody(caseBuilder.build());

            Future<RpcResult<Void>> resultFromOFLib = getMessageService().multipartRequest(mprInput.build(),
                    getCookie());
            ListenableFuture<RpcResult<Void>> resultLib = JdkFutureAdapters.listenInPoolThread(resultFromOFLib);

            Futures.addCallback(resultLib, new ResultCallback<UpdateTableOutput>(result) {
                @Override
                public UpdateTableOutput createResult() {
                    UpdateTableOutputBuilder queueStatsFromPortBuilder = new UpdateTableOutputBuilder()
                            .setTransactionId(new TransactionId(BigInteger.valueOf(xid)));
                    return queueStatsFromPortBuilder.build();
                }
            });
            return result;
        }
    }

    return new OFRpcTaskImpl(taskContext, cookie, input);
}