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.vpnservice.natservice.internal.VpnFloatingIpHandler.java

@Override
public void onRemoveFloatingIp(final BigInteger dpnId, String routerId, Uuid networkId, final String externalIp,
        String internalIp, final long label) {
    final String vpnName = NatUtil.getAssociatedVPN(dataBroker, networkId, LOG);
    if (vpnName == null) {
        LOG.info("No VPN associated with ext nw {} to handle remove floating ip configuration {} in router {}",
                networkId, externalIp, routerId);
        return;/*from  w ww.j  av  a  2s  . com*/
    }
    //Remove Prefix from BGP
    String rd = NatUtil.getVpnRd(dataBroker, vpnName);
    removePrefixFromBGP(rd, externalIp + "/32");

    //Remove custom FIB routes
    //Future<RpcResult<java.lang.Void>> removeFibEntry(RemoveFibEntryInput input);
    RemoveFibEntryInput input = new RemoveFibEntryInputBuilder().setVpnName(vpnName).setSourceDpid(dpnId)
            .setIpAddress(externalIp + "/32").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("Error in removing the label or custom fib entries", error);
        }

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

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

@Override
public void onAddFloatingIp(final BigInteger dpnId, final String routerId, final Uuid networkId,
        final String interfaceName, final InternalToExternalPortMap mapping) {
    String externalIp = mapping.getExternalIp();
    String internalIp = mapping.getInternalIp();
    Uuid floatingIpId = mapping.getExternalId();
    Uuid subnetId = NatUtil.getFloatingIpPortSubnetIdFromFloatingIpId(dataBroker, floatingIpId);
    String floatingIpPortMacAddress = NatUtil.getFloatingIpPortMacFromFloatingIpId(dataBroker, floatingIpId);
    Optional<Subnets> externalSubnet = NatUtil.getOptionalExternalSubnets(dataBroker, subnetId);
    final String vpnName = externalSubnet.isPresent() ? subnetId.getValue()
            : NatUtil.getAssociatedVPN(dataBroker, networkId, LOG);
    final String subnetVpnName = externalSubnet.isPresent() ? subnetId.getValue() : null;
    if (vpnName == null) {
        LOG.info("No VPN associated with ext nw {} to handle add floating ip configuration {} in router {}",
                networkId, externalIp, routerId);
        return;/*from   w  ww. ja  v  a2  s . co m*/
    }
    String rd = NatUtil.getVpnRd(dataBroker, vpnName);
    String nextHopIp = NatUtil.getEndpointIpAddressForDPN(dataBroker, dpnId);
    LOG.debug("Nexthop ip for prefix {} is {}", externalIp, nextHopIp);
    WriteTransaction writeTx = dataBroker.newWriteOnlyTransaction();
    ProviderTypes provType = NatEvpnUtil.getExtNwProvTypeFromRouterName(dataBroker, routerId);
    if (provType == null) {
        return;
    }
    if (provType == ProviderTypes.VXLAN) {
        Uuid floatingIpInterface = NatEvpnUtil.getFloatingIpInterfaceIdFromFloatingIpId(dataBroker,
                floatingIpId);
        evpnDnatFlowProgrammer.onAddFloatingIp(dpnId, routerId, vpnName, internalIp, externalIp, networkId,
                interfaceName, floatingIpInterface.getValue(), floatingIpPortMacAddress, rd, nextHopIp,
                writeTx);
        if (writeTx != null) {
            writeTx.submit();
        }
        return;
    }

    if (nvpnManager.getEnforceOpenstackSemanticsConfig()) {
        NatOverVxlanUtil.validateAndCreateVxlanVniPool(dataBroker, nvpnManager, idManager,
                NatConstants.ODL_VNI_POOL_NAME);
    }

    GenerateVpnLabelInput labelInput = new GenerateVpnLabelInputBuilder().setVpnName(vpnName)
            .setIpPrefix(externalIp).build();
    Future<RpcResult<GenerateVpnLabelOutput>> labelFuture = vpnService.generateVpnLabel(labelInput);

    ListenableFuture<RpcResult<Void>> future = Futures.transform(
            JdkFutureAdapters.listenInPoolThread(labelFuture),
            (AsyncFunction<RpcResult<GenerateVpnLabelOutput>, RpcResult<Void>>) result -> {
                if (result.isSuccessful()) {
                    GenerateVpnLabelOutput output = result.getResult();
                    long label = output.getLabel();
                    LOG.debug("Generated label {} for prefix {}", label, externalIp);
                    floatingIPListener.updateOperationalDS(routerId, interfaceName, label, internalIp,
                            externalIp);
                    //Inform BGP
                    long l3vni = 0;
                    if (nvpnManager.getEnforceOpenstackSemanticsConfig()) {
                        l3vni = NatOverVxlanUtil.getInternetVpnVni(idManager, vpnName, l3vni).longValue();
                    }
                    NatUtil.addPrefixToBGP(dataBroker, bgpManager, fibManager, vpnName, rd, subnetId,
                            externalIp + "/32", nextHopIp, networkId.getValue(), floatingIpPortMacAddress,
                            label, l3vni, LOG, RouteOrigin.STATIC, dpnId);

                    List<Instruction> instructions = new ArrayList<>();
                    List<ActionInfo> actionsInfos = new ArrayList<>();
                    actionsInfos.add(new ActionNxResubmit(NwConstants.PDNAT_TABLE));
                    instructions.add(new InstructionApplyActions(actionsInfos).buildInstruction(0));
                    makeTunnelTableEntry(vpnName, dpnId, label, instructions);

                    //Install custom FIB routes
                    List<ActionInfo> actionInfoFib = new ArrayList<>();
                    List<Instruction> customInstructions = new ArrayList<>();
                    actionInfoFib.add(
                            new ActionSetFieldEthernetDestination(new MacAddress(floatingIpPortMacAddress)));
                    customInstructions.add(new InstructionApplyActions(actionInfoFib).buildInstruction(0));
                    customInstructions
                            .add(new InstructionGotoTable(NwConstants.PDNAT_TABLE).buildInstruction(1));

                    makeLFibTableEntry(dpnId, label, NwConstants.PDNAT_TABLE);
                    CreateFibEntryInput input = new CreateFibEntryInputBuilder().setVpnName(vpnName)
                            .setSourceDpid(dpnId).setInstruction(customInstructions)
                            .setIpAddress(externalIp + "/32").setServiceId(label)
                            .setInstruction(customInstructions).build();
                    //Future<RpcResult<java.lang.Void>> createFibEntry(CreateFibEntryInput input);
                    Future<RpcResult<Void>> future1 = fibService.createFibEntry(input);
                    LOG.debug("Add Floating Ip {} , found associated to fixed port {}", externalIp,
                            interfaceName);
                    if (floatingIpPortMacAddress != null) {
                        String networkVpnName = NatUtil.getAssociatedVPN(dataBroker, networkId, LOG);
                        vpnManager.setupSubnetMacIntoVpnInstance(networkVpnName, subnetVpnName,
                                floatingIpPortMacAddress, dpnId, writeTx, NwConstants.ADD_FLOW);
                        vpnManager.setupArpResponderFlowsToExternalNetworkIps(routerId,
                                Collections.singleton(externalIp), floatingIpPortMacAddress, dpnId, networkId,
                                writeTx, NwConstants.ADD_FLOW);
                        writeTx.submit();
                    }
                    return JdkFutureAdapters.listenInPoolThread(future1);
                } else {
                    String errMsg = String.format("Could not retrieve the label for prefix %s in VPN %s, %s",
                            externalIp, vpnName, result.getErrors());
                    LOG.error(errMsg);
                    return Futures.immediateFailedFuture(new RuntimeException(errMsg));
                }
            });

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

        @Override
        public void onFailure(Throwable error) {
            LOG.error("Error in generate label or fib install process", error);
        }

        @Override
        public void onSuccess(RpcResult<Void> result) {
            if (result.isSuccessful()) {
                LOG.info("Successfully installed custom FIB routes for prefix {}", externalIp);
            } else {
                LOG.error("Error in rpc call to create custom Fib entries for prefix {} in DPN {}, {}",
                        externalIp, dpnId, result.getErrors());
            }
        }
    });

    // Handle GARP transmission
    final IpAddress extrenalAddress = IpAddressBuilder.getDefaultInstance(externalIp);
    sendGarpOnInterface(dpnId, networkId, extrenalAddress, floatingIpPortMacAddress);

}

From source file:org.opendaylight.openflowplugin.applications.frsync.impl.strategy.SyncPlanPushStrategyIncrementalImpl.java

ListenableFuture<RpcResult<Void>> addMissingFlows(final NodeId nodeId,
        final InstanceIdentifier<FlowCapableNode> nodeIdent,
        final Map<TableKey, ItemSyncBox<Flow>> flowsInTablesSyncBox, final SyncCrudCounters counters) {
    if (flowsInTablesSyncBox.isEmpty()) {
        LOG.trace("no tables in config for node: {} -> SKIPPING", nodeId.getValue());
        return RpcResultBuilder.<Void>success().buildFuture();
    }/*from   ww  w .ja v  a 2s .c o  m*/

    final List<ListenableFuture<RpcResult<AddFlowOutput>>> allResults = new ArrayList<>();
    final List<ListenableFuture<RpcResult<UpdateFlowOutput>>> allUpdateResults = new ArrayList<>();
    final CrudCounts flowCrudCounts = counters.getFlowCrudCounts();

    for (Map.Entry<TableKey, ItemSyncBox<Flow>> flowsInTableBoxEntry : flowsInTablesSyncBox.entrySet()) {
        final TableKey tableKey = flowsInTableBoxEntry.getKey();
        final ItemSyncBox<Flow> flowSyncBox = flowsInTableBoxEntry.getValue();

        final KeyedInstanceIdentifier<Table, TableKey> tableIdent = nodeIdent.child(Table.class, tableKey);

        for (final Flow flow : flowSyncBox.getItemsToPush()) {
            final KeyedInstanceIdentifier<Flow, FlowKey> flowIdent = tableIdent.child(Flow.class,
                    flow.getKey());

            LOG.trace("adding flow {} in table {} - absent on device {} match{}", flow.getId(), tableKey,
                    nodeId, flow.getMatch());

            allResults.add(JdkFutureAdapters.listenInPoolThread(flowForwarder.add(flowIdent, flow, nodeIdent)));
            flowCrudCounts.incAdded();
        }

        for (final ItemSyncBox.ItemUpdateTuple<Flow> flowUpdate : flowSyncBox.getItemsToUpdate()) {
            final Flow existingFlow = flowUpdate.getOriginal();
            final Flow updatedFlow = flowUpdate.getUpdated();

            final KeyedInstanceIdentifier<Flow, FlowKey> flowIdent = tableIdent.child(Flow.class,
                    updatedFlow.getKey());
            LOG.trace("flow {} in table {} - needs update on device {} match{}", updatedFlow.getId(), tableKey,
                    nodeId, updatedFlow.getMatch());

            allUpdateResults.add(JdkFutureAdapters
                    .listenInPoolThread(flowForwarder.update(flowIdent, existingFlow, updatedFlow, nodeIdent)));
            flowCrudCounts.incUpdated();
        }
    }

    final ListenableFuture<RpcResult<Void>> singleVoidAddResult = Futures.transform(
            Futures.allAsList(allResults),
            ReconcileUtil.<AddFlowOutput>createRpcResultCondenser("flow adding"));

    final ListenableFuture<RpcResult<Void>> singleVoidUpdateResult = Futures.transform(
            Futures.allAsList(allUpdateResults),
            ReconcileUtil.<UpdateFlowOutput>createRpcResultCondenser("flow updating"));

    return Futures.transform(Futures.allAsList(singleVoidAddResult, singleVoidUpdateResult),
            ReconcileUtil.<Void>createRpcResultCondenser("flow add/update"));
}

From source file:org.opendaylight.openflowplugin.applications.statistics.manager.impl.StatRpcMsgManagerImpl.java

@Override
public <T extends TransactionAware, D extends DataObject> void registrationRpcFutureCallBack(
        final Future<RpcResult<T>> future, final D inputObj, final NodeRef nodeRef,
        final SettableFuture<TransactionId> resultTransId) {

    class FutureCallbackImpl implements FutureCallback<RpcResult<? extends TransactionAware>> {
        @Override/*  w w w  .j  av  a  2 s  .c  o m*/
        public void onSuccess(final RpcResult<? extends TransactionAware> result) {
            final TransactionId id = result.getResult().getTransactionId();
            final NodeKey nodeKey = nodeRef.getValue().firstKeyOf(Node.class, NodeKey.class);
            if (id == null) {
                String[] multipartRequestName = result.getResult().getClass().getSimpleName()
                        .split("(?=\\p{Upper})");
                LOG.warn("Node [{}] does not support statistics request type : {}", nodeKey.getId(),
                        Joiner.on(" ").join(
                                Arrays.copyOfRange(multipartRequestName, 2, multipartRequestName.length - 2)));
            } else {
                if (resultTransId != null) {
                    resultTransId.set(id);
                }
                final String cacheKey = buildCacheKey(id, nodeKey.getId());
                final TransactionCacheContainer<? super TransactionAware> container = new TransactionCacheContainerImpl<>(
                        id, inputObj, nodeKey.getId());
                txCache.put(cacheKey, container);
            }
        }

        @Override
        public void onFailure(final Throwable t) {
            LOG.warn("Response Registration for Statistics RPC call fail!", t);
        }

    }

    Futures.addCallback(JdkFutureAdapters.listenInPoolThread(future), new FutureCallbackImpl());
}

From source file:org.opendaylight.netide.shim.ShimRelay.java

public <E extends DataObject> void sendResponseToCore(Future<RpcResult<E>> switchReply,
        final ZeroMQBaseConnector coreConnector, final short ofVersion, final long xId, final long datapathId,
        final int moduleId) {

    Futures.addCallback(JdkFutureAdapters.listenInPoolThread(switchReply), new FutureCallback<RpcResult<E>>() {
        @Override//from  w w w  .j  a va  2  s  . c  o m
        public void onSuccess(RpcResult<E> rpcReply) {
            if (rpcReply.isSuccessful()) {
                E result = rpcReply.getResult();

                sendOpenFlowMessageToCore(coreConnector, result, ofVersion, xId, datapathId, moduleId);
            } else {
                for (RpcError rpcError : rpcReply.getErrors()) {
                    LOG.info("SHIM RELAY: error in communication with switch: {}", rpcError.getMessage());
                }
            }
        }

        @Override
        public void onFailure(Throwable t) {
            LOG.info("SHIM RELAY: failure on communication with switch");
        }
    });
}

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

/**
 * send hello reply without versionBitmap
 * @param helloVersion initial hello version for openflow connection negotiation
 * @param helloXid transaction id/*ww w . j  a va  2 s  .co  m*/
 * @throws Exception
 */
private ListenableFuture<Void> sendHelloMessage(Short helloVersion, final Long helloXid) throws Exception {

    HelloInput helloInput = MessageFactory.createHelloInput(helloVersion, helloXid, versionOrder);

    final SettableFuture<Void> resultFtr = SettableFuture.create();

    LOG.debug("sending hello message: version{}, xid={}, version bitmap={}", helloVersion, helloXid,
            MessageFactory.digVersions(helloInput.getElements()));

    Future<RpcResult<Void>> helloResult = connectionAdapter.hello(helloInput);

    ListenableFuture<RpcResult<Void>> rpcResultListenableFuture = JdkFutureAdapters
            .listenInPoolThread(helloResult);
    Futures.addCallback(rpcResultListenableFuture, new FutureCallback<RpcResult<Void>>() {
        @Override
        public void onSuccess(RpcResult<Void> result) {
            if (result.isSuccessful()) {
                LOG.debug("hello successfully sent, xid={}, addr={}", helloXid,
                        connectionAdapter.getRemoteAddress());
                resultFtr.set(null);
            } else {
                for (RpcError error : result.getErrors()) {
                    LOG.debug("hello sending failed [{}]: i:{} s:{} m:{}, addr:{}", helloXid, error.getInfo(),
                            error.getSeverity(), error.getMessage(), connectionAdapter.getRemoteAddress());
                    if (error.getCause() != null) {
                        LOG.trace("DETAIL of sending hello failure", error.getCause());
                    }
                }
                resultFtr.cancel(false);
                handshakeListener.onHandshakeFailure();
            }
        }

        @Override
        public void onFailure(Throwable t) {
            LOG.warn("sending of hello failed seriously [{}, addr:{}]: {}", helloXid,
                    connectionAdapter.getRemoteAddress(), t.getMessage());
            LOG.trace("DETAIL of sending of hello failure:", t);
            resultFtr.cancel(false);
            handshakeListener.onHandshakeFailure();
        }
    });
    LOG.trace("sending hello message [{}] - result hooked ..", helloXid);
    return resultFtr;
}

From source file:org.opendaylight.netide.shim.ShimSwitchConnectionHandlerImpl.java

public void collectGetFeaturesOuput(Future<RpcResult<GetFeaturesOutput>> switchReply,
        final ConnectionAdapter connectionAdapter) {
    Futures.addCallback(JdkFutureAdapters.listenInPoolThread(switchReply),
            new FutureCallback<RpcResult<GetFeaturesOutput>>() {
                @Override/*from  ww  w.j  av  a  2  s  . co  m*/
                public void onSuccess(RpcResult<GetFeaturesOutput> rpcFeatures) {
                    if (rpcFeatures.isSuccessful()) {
                        GetFeaturesOutput featureOutput = rpcFeatures.getResult();
                        // Register Switch connection/DatapathId to registry
                        connectionRegistry.registerConnectionAdapter(connectionAdapter, featureOutput);
                        NodeUpdated nodeUpdated = nodeAdded(connectionAdapter);
                        notificationProviderService.offerNotification(nodeUpdated);

                    } else {
                        // Handshake failed
                        for (RpcError rpcError : rpcFeatures.getErrors()) {
                            LOG.info("handshake - features failure [{}]: i:{} | m:{} | s:{}",
                                    rpcError.getInfo(), rpcError.getMessage(), rpcError.getSeverity(),
                                    rpcError.getCause());
                        }
                    }
                }

                @Override
                public void onFailure(Throwable t) {
                    LOG.info("getting feature failed seriously [addr:{}]: {}",
                            connectionAdapter.getRemoteAddress(), t.getMessage());
                }
            });
}

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

public void onRemoveFloatingIp(final BigInteger dpnId, final String vpnName, final String externalIp,
        final String floatingIpInterface, final String floatingIpPortMacAddress) {
    /*// w w w.  j  a  v  a 2s.  c o m
     *  1) Remove the flow INTERNAL_TUNNEL_TABLE (table=36)-> PDNAT_TABLE (table=25) (SNAT VM on DPN1 is
     *     responding back to FIP VM on DPN2) {SNAT to DNAT traffic on different Hypervisor}
     *
     *  2) Remove the flow L3_FIB_TABLE (table=21)-> PDNAT_TABLE (table=25) (FIP VM1 to FIP VM2
     *    Traffic on Same Hypervisor) {DNAT to DNAT on Same Hypervisor}
     *
     *  3) Remove the flow L3_GW_MAC_TABLE (table=19)-> PDNAT_TABLE (table=25)
     *    (DC-GW is responding back to FIP VM) {DNAT Reverse traffic})
     *
     */
    String rd = NatUtil.getVpnRd(dataBroker, vpnName);
    if (rd == null) {
        LOG.error("NAT Service : Could not retrieve RD value from VPN Name {}  ", vpnName);
        return;
    }
    long l3Vni = NatEvpnUtil.getL3Vni(dataBroker, rd);
    if (l3Vni == NatConstants.DEFAULT_L3VNI_VALUE) {
        LOG.error("NAT Service : Could not retrieve L3VNI value from RD {} in ", rd);
        return;
    }
    //Remove Prefix from BGP
    NatUtil.removePrefixFromBGP(dataBroker, bgpManager, fibManager, rd, externalIp + "/32", vpnName, LOG);

    //Remove the flow for INTERNAL_TUNNEL_TABLE (table=36)-> PDNAT_TABLE (table=25)
    removeTunnelTableEntry(dpnId, l3Vni);

    //Remove custom FIB routes flow for L3_FIB_TABLE (table=21)-> PDNAT_TABLE (table=25)
    RemoveFibEntryInput input = new RemoveFibEntryInputBuilder().setVpnName(vpnName).setSourceDpid(dpnId)
            .setIpAddress(externalIp + "/32").setServiceId(l3Vni).build();
    Future<RpcResult<Void>> future = fibService.removeFibEntry(input);
    ListenableFuture<RpcResult<Void>> futureVxlan = JdkFutureAdapters.listenInPoolThread(future);
    Futures.addCallback(futureVxlan, new FutureCallback<RpcResult<Void>>() {

        @Override
        public void onFailure(Throwable error) {
            LOG.error("NAT Service : Error {} in custom fib routes remove process for Floating "
                    + "IP Prefix {} on DPN {}", error, externalIp, dpnId);
        }

        @Override
        public void onSuccess(RpcResult<Void> result) {
            if (result.isSuccessful()) {
                LOG.info("NAT Service : Successfully removed custom FIB routes for Floating "
                        + "IP Prefix {} on DPN {}", externalIp, dpnId);
            } else {
                LOG.error("NAT Service : Error {} in rpc call to remove custom Fib entries for Floating "
                        + "IP Prefix {} on DPN {}, {}", result.getErrors(), externalIp, dpnId);
            }
        }
    });

    long vpnId = NatUtil.getVpnId(dataBroker, vpnName);
    if (vpnId == NatConstants.INVALID_ID) {
        LOG.warn("NAT Service : Invalid Vpn Id is found for Vpn Name {}", vpnName);
    }
    //Remove the flow for L3_GW_MAC_TABLE (table=19)-> PDNAT_TABLE (table=25)
    NatEvpnUtil.removeL3GwMacTableEntry(dpnId, vpnId, floatingIpPortMacAddress, mdsalManager);

    //Read the FIP vpn-interface details from Operational l3vpn:vpn-interfaces model and delete from Operational DS
    InstanceIdentifier<VpnInterface> vpnIfIdentifier = NatUtil.getVpnInterfaceIdentifier(floatingIpInterface);
    Optional<VpnInterface> optionalVpnInterface = NatUtil.read(dataBroker, LogicalDatastoreType.OPERATIONAL,
            vpnIfIdentifier);
    if (optionalVpnInterface.isPresent()) {
        WriteTransaction writeOperTxn = dataBroker.newWriteOnlyTransaction();
        LOG.debug("NAT Service : Remove vpnInterface {} to Operational l3vpn:vpn-interfaces ",
                floatingIpInterface);
        writeOperTxn.delete(LogicalDatastoreType.OPERATIONAL, vpnIfIdentifier);
        if (writeOperTxn != null) {
            writeOperTxn.submit();
        }
    } else {
        LOG.debug("NAT Service : No vpnInterface {} found in Operational l3vpn:vpn-interfaces ",
                floatingIpInterface);
    }
}

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

void cleanupFibEntries(final BigInteger dpnId, final String vpnName, final String externalIp,
        final long label) {
    //Remove Prefix from BGP
    String rd = NatUtil.getVpnRd(dataBroker, vpnName);
    removePrefixFromBGP(rd, externalIp + "/32");

    //Remove custom FIB routes

    //Future<RpcResult<java.lang.Void>> removeFibEntry(RemoveFibEntryInput input);
    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// w w  w  . j a va 2  s .co m
                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("Error in removing the label or custom fib entries", error);
        }

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

From source file:org.opendaylight.openflowplugin.applications.frsync.impl.strategy.SyncPlanPushStrategyIncrementalImpl.java

ListenableFuture<RpcResult<Void>> removeRedundantFlows(final NodeId nodeId,
        final InstanceIdentifier<FlowCapableNode> nodeIdent, final Map<TableKey, ItemSyncBox<Flow>> removalPlan,
        final SyncCrudCounters counters) {
    if (removalPlan.isEmpty()) {
        LOG.trace("no tables in operational for node: {} -> SKIPPING", nodeId.getValue());
        return RpcResultBuilder.<Void>success().buildFuture();
    }//from w  w  w . j a v a 2  s  .  co m

    final List<ListenableFuture<RpcResult<RemoveFlowOutput>>> allResults = new ArrayList<>();
    final CrudCounts flowCrudCounts = counters.getFlowCrudCounts();

    for (final Map.Entry<TableKey, ItemSyncBox<Flow>> flowsPerTable : removalPlan.entrySet()) {
        final KeyedInstanceIdentifier<Table, TableKey> tableIdent = nodeIdent.child(Table.class,
                flowsPerTable.getKey());

        // loop flows on device and check if the are configured
        for (final Flow flow : flowsPerTable.getValue().getItemsToPush()) {
            final KeyedInstanceIdentifier<Flow, FlowKey> flowIdent = tableIdent.child(Flow.class,
                    flow.getKey());
            allResults.add(
                    JdkFutureAdapters.listenInPoolThread(flowForwarder.remove(flowIdent, flow, nodeIdent)));
            flowCrudCounts.incRemoved();
        }
    }

    final ListenableFuture<RpcResult<Void>> singleVoidResult = Futures.transform(Futures.allAsList(allResults),
            ReconcileUtil.<RemoveFlowOutput>createRpcResultCondenser("flow remove"));
    return Futures.transform(singleVoidResult,
            ReconcileUtil.chainBarrierFlush(PathUtil.digNodePath(nodeIdent), transactionService));

}