Search in sources :

Example 81 with Ports

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.destination.flowspec.flowspec.type.port._case.Ports in project netvirt by opendaylight.

the class TransportZoneNotificationUtil method getPortsNode.

@SuppressWarnings("unchecked")
private Optional<Node> getPortsNode(Uint64 dpnId) throws ReadFailedException {
    InstanceIdentifier<BridgeRefEntry> bridgeRefInfoPath = InstanceIdentifier.create(BridgeRefInfo.class).child(BridgeRefEntry.class, new BridgeRefEntryKey(dpnId));
    try {
        // FIXME: Read this through a cache
        Optional<BridgeRefEntry> optionalBridgeRefEntry = singleTxBroker.syncReadOptional(LogicalDatastoreType.OPERATIONAL, bridgeRefInfoPath);
        if (!optionalBridgeRefEntry.isPresent()) {
            LOG.error("no bridge ref entry found for dpnId {}", dpnId);
            return Optional.empty();
        }
        InstanceIdentifier<Node> nodeId = optionalBridgeRefEntry.get().getBridgeReference().getValue().firstIdentifierOf(Node.class);
        // FIXME: Read this through a cache
        Optional<Node> optionalNode = singleTxBroker.syncReadOptional(LogicalDatastoreType.OPERATIONAL, nodeId);
        if (!optionalNode.isPresent()) {
            LOG.error("missing node for dpnId {}", dpnId);
        }
        return optionalNode;
    } catch (ExecutionException | InterruptedException e) {
        LOG.error("Exception while getting ports for Node {}", dpnId, e);
    }
    return Optional.empty();
}
Also used : BridgeRefInfo(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.meta.rev160406.BridgeRefInfo) BridgeRefEntry(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.meta.rev160406.bridge.ref.info.BridgeRefEntry) Node(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node) BridgeRefEntryKey(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.meta.rev160406.bridge.ref.info.BridgeRefEntryKey) ExecutionException(java.util.concurrent.ExecutionException)

Example 82 with Ports

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.destination.flowspec.flowspec.type.port._case.Ports in project netvirt by opendaylight.

the class ExternalNetworksChangeListener method associateExternalNetworkWithVPN.

private void associateExternalNetworkWithVPN(Networks network) {
    if (network.getRouterIds() != null) {
        List<Uuid> routerIds = network.getRouterIds();
        for (Uuid routerId : routerIds) {
            // long router = NatUtil.getVpnId(dataBroker, routerId.getValue());
            InstanceIdentifier<RouterPorts> routerPortsId = NatUtil.getRouterPortsId(routerId.getValue());
            Optional<RouterPorts> optRouterPorts = null;
            try {
                optRouterPorts = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, routerPortsId);
            } catch (ExecutionException | InterruptedException e) {
                LOG.error("associateExternalNetworkWithVPN: Exception while reading RouterPorts DS for the " + "router {} network {} ", routerId, network.getId().getValue(), e);
                continue;
            }
            if (!optRouterPorts.isPresent()) {
                LOG.debug("associateExternalNetworkWithVPN : Could not read Router Ports data object with id: {} " + "to handle associate ext nw {}", routerId, network.getId());
                continue;
            }
            RouterPorts routerPorts = optRouterPorts.get();
            for (Ports port : routerPorts.nonnullPorts().values()) {
                String portName = port.getPortName();
                Uint64 dpnId = NatUtil.getDpnForInterface(interfaceManager, portName);
                if (dpnId.equals(Uint64.ZERO)) {
                    LOG.debug("associateExternalNetworkWithVPN : DPN not found for {}, " + "skip handling of ext nw {} association", portName, network.getId());
                    continue;
                }
                for (InternalToExternalPortMap ipMap : port.nonnullInternalToExternalPortMap().values()) {
                    // remove all VPN related entries
                    coordinator.enqueueJob(NatConstants.NAT_DJC_PREFIX + ipMap.key(), () -> Collections.singletonList(txRunner.callWithNewReadWriteTransactionAndSubmit(CONFIGURATION, tx -> floatingIpListener.createNATFlowEntries(dpnId, portName, routerId.getValue(), network.getId(), ipMap, tx))), NatConstants.NAT_DJC_MAX_RETRIES);
                }
            }
        }
        // SNAT
        for (Uuid routerId : routerIds) {
            LOG.debug("associateExternalNetworkWithVPN() : for routerId {}", routerId);
            Uuid networkId = network.getId();
            if (networkId == null) {
                LOG.error("associateExternalNetworkWithVPN : networkId is null for the router ID {}", routerId);
                return;
            }
            final String vpnName = network.getVpnid().getValue();
            if (vpnName == null) {
                LOG.error("associateExternalNetworkWithVPN : No VPN associated with ext nw {} for router {}", networkId, routerId);
                return;
            }
            Uint64 dpnId = Uint64.valueOf("0");
            InstanceIdentifier<RouterToNaptSwitch> routerToNaptSwitch = NatUtil.buildNaptSwitchRouterIdentifier(routerId.getValue());
            Optional<RouterToNaptSwitch> rtrToNapt = Optional.empty();
            try {
                rtrToNapt = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, routerToNaptSwitch);
            } catch (ExecutionException | InterruptedException e) {
                LOG.error("associateExternalNetworkWithVPN: Exception while reading routerToNaptSwitch DS for the " + "router {}", routerId, e);
            }
            if (rtrToNapt.isPresent()) {
                dpnId = rtrToNapt.get().getPrimarySwitchId();
            }
            LOG.debug("associateExternalNetworkWithVPN : got primarySwitch as dpnId{} ", dpnId);
            if (dpnId == null || dpnId.equals(Uint64.ZERO)) {
                LOG.warn("associateExternalNetworkWithVPN : primary napt Switch not found for router {} on dpn: {}", routerId, dpnId);
                return;
            }
            final Uint64 finalDpnId = dpnId;
            coordinator.enqueueJob(NatConstants.NAT_DJC_PREFIX + routerId.getValue(), () -> Collections.singletonList(txRunner.callWithNewReadWriteTransactionAndSubmit(CONFIGURATION, confTx -> {
                Uint32 routerIdentifier = NatUtil.getVpnId(dataBroker, routerId.getValue());
                InstanceIdentifierBuilder<org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.intext.ip.map.IpMapping> idBuilder = InstanceIdentifier.builder(IntextIpMap.class).child(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.intext.ip.map.IpMapping.class, new org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.intext.ip.map.IpMappingKey(routerIdentifier));
                InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.intext.ip.map.IpMapping> id = idBuilder.build();
                Optional<org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.intext.ip.map.IpMapping> ipMapping = MDSALUtil.read(dataBroker, LogicalDatastoreType.OPERATIONAL, id);
                if (ipMapping.isPresent()) {
                    for (IpMap ipMap : ipMapping.get().nonnullIpMap().values()) {
                        String externalIp = ipMap.getExternalIp();
                        LOG.debug("associateExternalNetworkWithVPN : Calling advToBgpAndInstallFibAndTsFlows " + "for dpnId {},vpnName {} and externalIp {}", finalDpnId, vpnName, externalIp);
                        if (natMode == NatMode.Controller) {
                            externalRouterListener.advToBgpAndInstallFibAndTsFlows(finalDpnId, NwConstants.INBOUND_NAPT_TABLE, vpnName, routerIdentifier, routerId.getValue(), externalIp, network.getId(), null, /* external-router */
                            confTx);
                        }
                    }
                } else {
                    LOG.warn("associateExternalNetworkWithVPN: No ipMapping present fot the routerId {}", routerId);
                }
                Uint32 vpnId = NatUtil.getVpnId(dataBroker, vpnName);
                // Install 47 entry to point to 21
                if (natMode == NatMode.Controller) {
                    externalRouterListener.installNaptPfibEntriesForExternalSubnets(routerId.getValue(), finalDpnId, confTx);
                    if (vpnId.longValue() != -1) {
                        LOG.debug("associateExternalNetworkWithVPN : Calling externalRouterListener " + "installNaptPfibEntry for dpnId {} and vpnId {}", finalDpnId, vpnId);
                        externalRouterListener.installNaptPfibEntry(finalDpnId, vpnId, confTx);
                    }
                }
            })), NatConstants.NAT_DJC_MAX_RETRIES);
        }
    }
}
Also used : RouterPorts(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.RouterPorts) IntextIpMap(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.IntextIpMap) ExecutionException(java.util.concurrent.ExecutionException) InternalToExternalPortMap(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.router.ports.ports.InternalToExternalPortMap) Uint32(org.opendaylight.yangtools.yang.common.Uint32) RouterToNaptSwitch(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.napt.switches.RouterToNaptSwitch) RouterPorts(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.RouterPorts) Ports(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.router.ports.Ports) IpMap(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.intext.ip.map.ip.mapping.IpMap) IntextIpMap(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.IntextIpMap) Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) Uint64(org.opendaylight.yangtools.yang.common.Uint64)

Example 83 with Ports

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.destination.flowspec.flowspec.type.port._case.Ports in project netvirt by opendaylight.

the class AbstractSnatService method removeLearntIpPorts.

private void removeLearntIpPorts(Routers routers) {
    LOG.info("removeLearntIpPorts for router {} and network {}", routers.getRouterName(), routers.getNetworkId());
    String networkId = routers.getNetworkId().getValue();
    LearntVpnVipToPortData learntVpnVipToPortData = NatUtil.getLearntVpnVipToPortData(dataBroker);
    if (learntVpnVipToPortData == null) {
        LOG.info("removeLearntIpPorts, no learned ports present");
        return;
    }
    LearntVpnVipToPortDataBuilder learntVpnVipToPortDataBuilder = new LearntVpnVipToPortDataBuilder();
    List<LearntVpnVipToPort> learntVpnVipToPortList = new ArrayList<>();
    for (LearntVpnVipToPort learntVpnVipToPort : learntVpnVipToPortData.nonnullLearntVpnVipToPort().values()) {
        if (!networkId.equals(learntVpnVipToPort.getVpnName())) {
            LOG.info("The learned port belongs to Vpn {} hence not removing", learntVpnVipToPort.getVpnName());
            learntVpnVipToPortList.add(learntVpnVipToPort);
        } else {
            String externalSubNetId = null;
            for (ExternalIps externalIp : routers.nonnullExternalIps().values()) {
                if (!NWUtil.isIpv4Address(externalIp.getIpAddress())) {
                    // In this class we handle only IPv4 use-cases.
                    continue;
                }
                externalSubNetId = externalIp.getSubnetId().getValue();
                break;
            }
            if (externalSubNetId == null) {
                LOG.info("removeLearntIpPorts no external Ipv4 address present on router {}", routers.getRouterName());
                return;
            }
            String prefix = learntVpnVipToPort.getPortFixedip() + "/32";
            NatUtil.deletePrefixToInterface(dataBroker, NatUtil.getVpnId(dataBroker, externalSubNetId), prefix);
        }
    }
    try {
        learntVpnVipToPortDataBuilder.setLearntVpnVipToPort(learntVpnVipToPortList);
        InstanceIdentifier<LearntVpnVipToPortData> learntVpnVipToPortDataId = NatUtil.getLearntVpnVipToPortDataId();
        SingleTransactionDataBroker.syncWrite(dataBroker, LogicalDatastoreType.OPERATIONAL, learntVpnVipToPortDataId, learntVpnVipToPortDataBuilder.build());
    } catch (TransactionCommitFailedException e) {
        LOG.warn("Failed to remove removeLearntIpPorts with error {}", e.getMessage());
    }
}
Also used : TransactionCommitFailedException(org.opendaylight.mdsal.common.api.TransactionCommitFailedException) LearntVpnVipToPortDataBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.LearntVpnVipToPortDataBuilder) ArrayList(java.util.ArrayList) LearntVpnVipToPort(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.learnt.vpn.vip.to.port.data.LearntVpnVipToPort) LearntVpnVipToPortData(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.LearntVpnVipToPortData) ExternalIps(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.routers.ExternalIps)

Example 84 with Ports

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.destination.flowspec.flowspec.type.port._case.Ports in project netvirt by opendaylight.

the class NatTunnelInterfaceStateListener method hndlTepAddForDnatInEachRtr.

private void hndlTepAddForDnatInEachRtr(RoutersList router, Uint32 routerId, String nextHopIp, Uint64 tepAddedDpnId, ProviderTypes extNwProvType, TypedWriteTransaction<Configuration> confTx) {
    // DNAT : Advertise the new route to the floating IP having the new TEP IP as the next hop IP
    final String routerName = router.getRouter();
    InstanceIdentifier<RouterPorts> routerPortsId = NatUtil.getRouterPortsId(routerName);
    Optional<RouterPorts> optRouterPorts;
    try {
        optRouterPorts = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, routerPortsId);
    } catch (ExecutionException | InterruptedException e) {
        LOG.error("hndlTepAddForDnatInEachRtr: Exception while reading RouterPorts DS for the router {}", routerName, e);
        return;
    }
    if (!optRouterPorts.isPresent()) {
        LOG.debug("hndlTepAddForDnatInEachRtr : DNAT -> Could not read Router Ports data object with id: {} " + "from DNAT FloatinIpInfo", routerName);
        return;
    }
    RouterPorts routerPorts = optRouterPorts.get();
    Uuid extNwId = routerPorts.getExternalNetworkId();
    final String vpnName = NatUtil.getAssociatedVPN(dataBroker, extNwId);
    if (vpnName == null) {
        LOG.info("hndlTepAddForDnatInEachRtr : DNAT -> No External VPN associated with ext nw {} for router {}", extNwId, routerName);
        return;
    }
    String rd = NatUtil.getVpnRd(dataBroker, vpnName);
    if (extNwProvType == null) {
        return;
    }
    String gwMacAddress = null;
    Uint32 l3Vni = Uint32.ZERO;
    if (extNwProvType == ProviderTypes.VXLAN) {
        // Get the External Gateway MAC Address which is Router gateway MAC address for SNAT
        gwMacAddress = NatUtil.getExtGwMacAddFromRouterName(dataBroker, routerName);
        if (gwMacAddress != null) {
            LOG.debug("hndlTepAddForDnatInEachRtr : External GwMAC address {} found for External Router ID {}", gwMacAddress, routerId);
        } else {
            LOG.error("hndlTepAddForDnatInEachRtr : No External GwMAC address found for External Router ID {}", routerId);
            return;
        }
        // get l3Vni value for external VPN
        l3Vni = NatEvpnUtil.getL3Vni(dataBroker, rd);
        if (l3Vni == NatConstants.DEFAULT_L3VNI_VALUE) {
            LOG.debug("hndlTepAddForDnatInEachRtr : L3VNI value is not configured in Internet VPN {} and RD {} " + "Carve-out L3VNI value from OpenDaylight VXLAN VNI Pool and continue to installing " + "NAT flows", vpnName, rd);
            l3Vni = natOverVxlanUtil.getInternetVpnVni(vpnName, routerId);
        }
    }
    for (Ports port : routerPorts.nonnullPorts().values()) {
        // Get the DPN on which this interface resides
        final String interfaceName = port.getPortName();
        final Uint64 fipCfgdDpnId = NatUtil.getDpnForInterface(interfaceService, interfaceName);
        if (fipCfgdDpnId.equals(Uint64.ZERO)) {
            LOG.info("hndlTepAddForDnatInEachRtr : DNAT->Skip processing Floating ip configuration for the port {}," + "since no DPN present for it", interfaceName);
            continue;
        }
        if (!fipCfgdDpnId.equals(tepAddedDpnId)) {
            LOG.debug("hndlTepAddForDnatInEachRtr : DNAT -> TEP added DPN {} is not the DPN {} which has the " + "floating IP configured for the port: {}", tepAddedDpnId, fipCfgdDpnId, interfaceName);
            continue;
        }
        for (InternalToExternalPortMap intExtPortMap : port.nonnullInternalToExternalPortMap().values()) {
            final String internalIp = intExtPortMap.getInternalIp();
            final String externalIp = intExtPortMap.getExternalIp();
            LOG.debug("hndlTepAddForDnatInEachRtr : DNAT -> Advertising the FIB route to the floating IP {} " + "configured for the port: {}", externalIp, interfaceName);
            Uint32 serviceId = null;
            String fibExternalIp = NatUtil.validateAndAddNetworkMask(externalIp);
            if (extNwProvType == ProviderTypes.VXLAN) {
                LOG.debug("hndlTepAddForDnatInEachRtr : DNAT -> Advertise the route to the externalIp {} " + "having nextHopIp {}", externalIp, nextHopIp);
                NatEvpnUtil.addRoutesForVxLanProvType(dataBroker, bgpManager, fibManager, vpnName, rd, externalIp, nextHopIp, l3Vni, interfaceName, gwMacAddress, confTx, RouteOrigin.STATIC, fipCfgdDpnId, extNwId);
                serviceId = l3Vni;
            } else {
                serviceId = floatingIPListener.getOperationalIpMapping(routerName, interfaceName, internalIp);
                if (serviceId == null || serviceId == NatConstants.INVALID_ID) {
                    LOG.error("hndlTepAddForDnatInEachRtr : DNAT -> Unable to advertise to the DC GW since label " + "is invalid");
                    return;
                }
                LOG.debug("hndlTepAddForDnatInEachRtr : DNAT -> Advertise the route to the externalIp {} " + "having nextHopIp {}", externalIp, nextHopIp);
                Uint32 l3vni = Uint32.ZERO;
                if (NatUtil.isOpenStackVniSemanticsEnforcedForGreAndVxlan(elanManager, extNwProvType)) {
                    l3vni = natOverVxlanUtil.getInternetVpnVni(vpnName, l3vni);
                }
                NatUtil.addPrefixToBGP(dataBroker, bgpManager, fibManager, vpnName, rd, fibExternalIp, nextHopIp, null, null, serviceId, l3vni, RouteOrigin.STATIC, fipCfgdDpnId);
            }
            // Install custom FIB routes (Table 21 -> Push MPLS label to Tunnel port
            List<Instruction> customInstructions = new ArrayList<>();
            customInstructions.add(new InstructionGotoTable(NwConstants.PDNAT_TABLE).buildInstruction(0));
            CreateFibEntryInput input = new CreateFibEntryInputBuilder().setVpnName(vpnName).setSourceDpid(fipCfgdDpnId).setInstruction(customInstructions).setIpAddressSource(FibEntryInputs.IpAddressSource.FloatingIP).setIpAddress(fibExternalIp).setServiceId(serviceId).setInstruction(customInstructions).build();
            ListenableFuture<RpcResult<CreateFibEntryOutput>> listenableFuture = fibRpcService.createFibEntry(input);
            Futures.addCallback(listenableFuture, new FutureCallback<RpcResult<CreateFibEntryOutput>>() {

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

                @Override
                public void onSuccess(@NonNull RpcResult<CreateFibEntryOutput> result) {
                    if (result.isSuccessful()) {
                        LOG.info("hndlTepAddForDnatInEachRtr : DNAT -> Successfully installed custom FIB routes " + "for prefix {}", externalIp);
                    } else {
                        LOG.error("hndlTepAddForDnatInEachRtr : DNAT -> Error in rpc call to create custom Fib " + "entries for prefix {} in DPN {}, {}", externalIp, fipCfgdDpnId, result.getErrors());
                    }
                }
            }, MoreExecutors.directExecutor());
        }
    }
}
Also used : RouterPorts(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.RouterPorts) ArrayList(java.util.ArrayList) Instruction(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.Instruction) ExecutionException(java.util.concurrent.ExecutionException) Uint32(org.opendaylight.yangtools.yang.common.Uint32) InternalToExternalPortMap(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.router.ports.ports.InternalToExternalPortMap) InstructionGotoTable(org.opendaylight.genius.mdsalutil.instructions.InstructionGotoTable) CreateFibEntryInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fib.rpc.rev160121.CreateFibEntryInputBuilder) CreateFibEntryOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fib.rpc.rev160121.CreateFibEntryOutput) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) RouterPorts(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.RouterPorts) Ports(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.router.ports.Ports) CreateFibEntryInput(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fib.rpc.rev160121.CreateFibEntryInput) Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) Uint64(org.opendaylight.yangtools.yang.common.Uint64)

Example 85 with Ports

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.destination.flowspec.flowspec.type.port._case.Ports in project netvirt by opendaylight.

the class NatTepChangeListener method hndlTepDelForDnatInEachRtr.

private boolean hndlTepDelForDnatInEachRtr(RoutersList router, Uint32 routerId, Uint64 tepDeletedDpnId, ProviderTypes extNwProvType) {
    // DNAT : Withdraw the routes from the BGP
    String routerName = router.getRouter();
    Boolean isFipExists = Boolean.FALSE;
    LOG.debug("hndlTepDelForDnatInEachRtr : DNAT -> Trying to clear routes to the Floating IP " + "associated to the router {}", routerName);
    InstanceIdentifier<RouterPorts> routerPortsId = NatUtil.getRouterPortsId(routerName);
    Optional<RouterPorts> optRouterPorts;
    try {
        optRouterPorts = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, routerPortsId);
    } catch (ExecutionException | InterruptedException e) {
        LOG.error("hndlTepDelForDnatInEachRtr: Exception while reading RouterPorts DS for the router {}", routerName, e);
        return isFipExists;
    }
    if (!optRouterPorts.isPresent()) {
        LOG.debug("hndlTepDelForDnatInEachRtr : DNAT -> Could not read Router Ports data object with id: {} " + "from DNAT FloatingIpInfo", routerName);
        return isFipExists;
    }
    RouterPorts routerPorts = optRouterPorts.get();
    Uuid extNwId = routerPorts.getExternalNetworkId();
    final String vpnName = NatUtil.getAssociatedVPN(dataBroker, extNwId);
    if (vpnName == null) {
        LOG.error("hndlTepDelForDnatInEachRtr : DNAT -> No External VPN associated with Ext N/W {} for Router {}", extNwId, routerName);
        return isFipExists;
    }
    String rd = NatUtil.getVpnRd(dataBroker, vpnName);
    if (extNwProvType == null) {
        return isFipExists;
    }
    Uint32 l3Vni = Uint32.ZERO;
    if (extNwProvType == ProviderTypes.VXLAN) {
        // get l3Vni value for external VPN
        l3Vni = NatEvpnUtil.getL3Vni(dataBroker, rd);
        if (l3Vni == NatConstants.DEFAULT_L3VNI_VALUE) {
            LOG.debug("hndlTepDelForDnatInEachRtr : L3VNI value is not configured in Internet VPN {} and RD {} " + "Carve-out L3VNI value from OpenDaylight VXLAN VNI Pool and continue to installing " + "NAT flows", vpnName, rd);
            l3Vni = natOverVxlanUtil.getInternetVpnVni(vpnName, routerId);
        }
    }
    Map<PortsKey, Ports> interfacesMap = routerPorts.nonnullPorts();
    for (Ports port : interfacesMap.values()) {
        // Get the DPN on which this interface resides
        String interfaceName = port.getPortName();
        Uint64 fipCfgdDpnId = NatUtil.getDpnForInterface(interfaceService, interfaceName);
        if (fipCfgdDpnId.equals(Uint64.ZERO)) {
            LOG.info("hndlTepDelForDnatInEachRtr : DNAT -> Abort processing Floating ip configuration. " + "No DPN for port : {}", interfaceName);
            continue;
        }
        if (!fipCfgdDpnId.equals(tepDeletedDpnId)) {
            LOG.info("hndlTepDelForDnatInEachRtr : DNAT -> TEP deleted DPN {} is not the DPN {} which has the " + "floating IP configured for the port: {}", tepDeletedDpnId, fipCfgdDpnId, interfaceName);
            continue;
        }
        isFipExists = Boolean.TRUE;
        Map<InternalToExternalPortMapKey, InternalToExternalPortMap> keyInternalToExternalPortMapMap = port.nonnullInternalToExternalPortMap();
        for (InternalToExternalPortMap intExtPortMap : keyInternalToExternalPortMapMap.values()) {
            String internalIp = intExtPortMap.getInternalIp();
            String externalIp = intExtPortMap.getExternalIp();
            externalIp = NatUtil.validateAndAddNetworkMask(externalIp);
            LOG.debug("hndlTepDelForDnatInEachRtr : DNAT -> Withdrawing the FIB route to the floating IP {} " + "configured for the port: {}", externalIp, interfaceName);
            NatUtil.removePrefixFromBGP(bgpManager, fibManager, rd, externalIp, vpnName);
            Uint32 serviceId = null;
            if (extNwProvType == ProviderTypes.VXLAN) {
                serviceId = l3Vni;
            } else {
                serviceId = floatingIPListener.getOperationalIpMapping(routerName, interfaceName, internalIp);
                if (serviceId == null || serviceId == NatConstants.INVALID_ID) {
                    LOG.error("hndlTepDelForDnatInEachRtr : DNAT -> Unable to remove the table 21 entry pushing the" + " MPLS label to the tunnel since label is invalid");
                    continue;
                }
            }
            RemoveFibEntryInput input = new RemoveFibEntryInputBuilder().setVpnName(vpnName).setSourceDpid(fipCfgdDpnId).setIpAddress(externalIp).setServiceId(serviceId).setIpAddressSource(RemoveFibEntryInput.IpAddressSource.FloatingIP).build();
            ListenableFuture<RpcResult<RemoveFibEntryOutput>> future = fibRpcService.removeFibEntry(input);
            Futures.addCallback(future, new FutureCallback<RpcResult<RemoveFibEntryOutput>>() {

                @Override
                public void onFailure(Throwable error) {
                    LOG.error("hndlTepDelForDnatInEachRtr : DNAT -> Error in removing the table 21 entry pushing " + "the MPLS label to the tunnel since label is invalid ", error);
                }

                @Override
                public void onSuccess(RpcResult<RemoveFibEntryOutput> result) {
                    if (result.isSuccessful()) {
                        LOG.info("hndlTepDelForDnatInEachRtr : DNAT -> Successfully removed the entry pushing the " + "MPLS label to the tunnel");
                    } else {
                        LOG.error("hndlTepDelForDnatInEachRtr : DNAT -> Error in fib rpc call to remove the table " + "21 entry pushing the MPLS label to the tunnnel due to {}", result.getErrors());
                    }
                }
            }, MoreExecutors.directExecutor());
        }
    }
    return isFipExists;
}
Also used : InternalToExternalPortMapKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.router.ports.ports.InternalToExternalPortMapKey) RouterPorts(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.RouterPorts) RemoveFibEntryOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fib.rpc.rev160121.RemoveFibEntryOutput) RemoveFibEntryInput(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fib.rpc.rev160121.RemoveFibEntryInput) ExecutionException(java.util.concurrent.ExecutionException) Uint32(org.opendaylight.yangtools.yang.common.Uint32) InternalToExternalPortMap(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.router.ports.ports.InternalToExternalPortMap) PortsKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.router.ports.PortsKey) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) RouterPorts(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.RouterPorts) Ports(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.router.ports.Ports) Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) RemoveFibEntryInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fib.rpc.rev160121.RemoveFibEntryInputBuilder) Uint64(org.opendaylight.yangtools.yang.common.Uint64)

Aggregations

ArrayList (java.util.ArrayList)36 Uuid (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid)32 ExecutionException (java.util.concurrent.ExecutionException)22 Ports (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.router.ports.Ports)21 RouterPorts (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.RouterPorts)19 InternalToExternalPortMap (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.router.ports.ports.InternalToExternalPortMap)18 Port (org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.ports.attributes.ports.Port)13 Uint64 (org.opendaylight.yangtools.yang.common.Uint64)13 BigInteger (java.math.BigInteger)11 Test (org.junit.Test)11 MacAddress (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress)9 LearntVpnVipToPort (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.learnt.vpn.vip.to.port.data.LearntVpnVipToPort)9 Subnetmap (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.Subnetmap)9 PortsKey (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.router.ports.PortsKey)8 RpcResult (org.opendaylight.yangtools.yang.common.RpcResult)7 HashSet (java.util.HashSet)6 VpnPortipToPort (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.neutron.vpn.portip.port.data.VpnPortipToPort)6 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)5 ByteBuf (io.netty.buffer.ByteBuf)5 HashMap (java.util.HashMap)5