Search in sources :

Example 6 with AdjacenciesOp

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.AdjacenciesOp in project netvirt by opendaylight.

the class VpnInterfaceManager method processVpnInterfaceAdjacencies.

@SuppressWarnings("checkstyle:IllegalCatch")
protected void processVpnInterfaceAdjacencies(BigInteger dpnId, final int lportTag, String vpnName, String primaryRd, String interfaceName, final long vpnId, WriteTransaction writeConfigTxn, WriteTransaction writeOperTxn, final WriteTransaction writeInvTxn, Interface interfaceState) {
    InstanceIdentifier<VpnInterface> identifier = VpnUtil.getVpnInterfaceIdentifier(interfaceName);
    // Read NextHops
    InstanceIdentifier<Adjacencies> path = identifier.augmentation(Adjacencies.class);
    Optional<Adjacencies> adjacencies = VpnUtil.read(dataBroker, LogicalDatastoreType.CONFIGURATION, path);
    if (!adjacencies.isPresent()) {
        addVpnInterfaceToOperational(vpnName, interfaceName, dpnId, null, /*adjacencies*/
        lportTag, null, /*gwMac*/
        writeOperTxn);
        return;
    }
    // Get the rd of the vpn instance
    String nextHopIp = null;
    try {
        nextHopIp = InterfaceUtils.getEndpointIpAddressForDPN(dataBroker, dpnId);
    } catch (Exception e) {
        LOG.error("processVpnInterfaceAdjacencies: Unable to retrieve endpoint ip address for " + "dpnId {} for vpnInterface {} vpnName {}", dpnId, interfaceName, vpnName);
    }
    List<String> nhList = new ArrayList<>();
    if (nextHopIp != null) {
        nhList.add(nextHopIp);
        LOG.debug("processVpnInterfaceAdjacencies: NextHop for interface {} on dpn {} in vpn {} is {}", interfaceName, dpnId, vpnName, nhList);
    }
    Optional<String> gwMac = Optional.absent();
    String vpnInterfaceSubnetGwMacAddress = null;
    VpnInstanceOpDataEntry vpnInstanceOpData = VpnUtil.getVpnInstanceOpData(dataBroker, primaryRd);
    Long l3vni = vpnInstanceOpData.getL3vni();
    boolean isL3VpnOverVxLan = VpnUtil.isL3VpnOverVxLan(l3vni);
    VrfEntry.EncapType encapType = isL3VpnOverVxLan ? VrfEntry.EncapType.Vxlan : VrfEntry.EncapType.Mplsgre;
    VpnPopulator registeredPopulator = L3vpnRegistry.getRegisteredPopulator(encapType);
    List<Adjacency> nextHops = adjacencies.get().getAdjacency();
    List<Adjacency> value = new ArrayList<>();
    for (Adjacency nextHop : nextHops) {
        String rd = primaryRd;
        String nexthopIpValue = nextHop.getIpAddress().split("/")[0];
        if (vpnInstanceOpData.getBgpvpnType() == VpnInstanceOpDataEntry.BgpvpnType.BGPVPNInternet && NWUtil.isIpv4Address(nexthopIpValue)) {
            String prefix = nextHop.getIpAddress() == null ? "null" : VpnUtil.getIpPrefix(nextHop.getIpAddress());
            LOG.debug("processVpnInterfaceAdjacencies: UnsupportedOperation : Not Adding prefix {} to interface {}" + " as InternetVpn has an IPV4 address {}", prefix, interfaceName, vpnName);
            continue;
        }
        if (nextHop.getAdjacencyType() == AdjacencyType.PrimaryAdjacency) {
            String prefix = VpnUtil.getIpPrefix(nextHop.getIpAddress());
            Prefixes.PrefixCue prefixCue = nextHop.isPhysNetworkFunc() ? Prefixes.PrefixCue.PhysNetFunc : Prefixes.PrefixCue.None;
            LOG.debug("processVpnInterfaceAdjacencies: Adding prefix {} to interface {} with nextHops {} on dpn {}" + " for vpn {}", prefix, interfaceName, nhList, dpnId, vpnName);
            writeOperTxn.merge(LogicalDatastoreType.OPERATIONAL, VpnUtil.getPrefixToInterfaceIdentifier(VpnUtil.getVpnId(dataBroker, vpnName), prefix), VpnUtil.getPrefixToInterface(dpnId, interfaceName, prefix, nextHop.getSubnetId(), prefixCue), true);
            final Uuid subnetId = nextHop.getSubnetId();
            String gatewayIp = nextHop.getSubnetGatewayIp();
            if (gatewayIp == null) {
                Optional<String> gatewayIpOptional = VpnUtil.getVpnSubnetGatewayIp(dataBroker, subnetId);
                if (gatewayIpOptional.isPresent()) {
                    gatewayIp = gatewayIpOptional.get();
                }
            }
            if (gatewayIp != null) {
                gwMac = getMacAddressForSubnetIp(vpnName, interfaceName, gatewayIp);
                if (gwMac.isPresent()) {
                    // A valid mac-address is available for this subnet-gateway-ip
                    // Use this for programming ARP_RESPONDER table here.  And save this
                    // info into vpnInterface operational, so it can used in VrfEntryProcessor
                    // to populate L3_GW_MAC_TABLE there.
                    arpResponderHandler.addArpResponderFlow(dpnId, lportTag, interfaceName, gatewayIp, gwMac.get());
                    vpnInterfaceSubnetGwMacAddress = gwMac.get();
                } else {
                    // A valid mac-address is not available for this subnet-gateway-ip
                    // Use the connected-mac-address to configure ARP_RESPONDER Table.
                    // Save this connected-mac-address as gateway-mac-address for the
                    // VrfEntryProcessor to use this later to populate the L3_GW_MAC_TABLE.
                    gwMac = InterfaceUtils.getMacAddressFromInterfaceState(interfaceState);
                    if (gwMac.isPresent()) {
                        VpnUtil.setupGwMacIfExternalVpn(dataBroker, mdsalManager, dpnId, interfaceName, vpnId, writeInvTxn, NwConstants.ADD_FLOW, gwMac.get());
                        arpResponderHandler.addArpResponderFlow(dpnId, lportTag, interfaceName, gatewayIp, gwMac.get());
                    } else {
                        LOG.error("processVpnInterfaceAdjacencies: Gateway MAC for subnet ID {} could not be " + "obtained, cannot create ARP responder flow for interface name {}, vpnName {}, " + "gwIp {}", subnetId, interfaceName, vpnName, gatewayIp);
                    }
                }
            } else {
                LOG.warn("processVpnInterfaceAdjacencies: Gateway IP for subnet ID {} could not be obtained, " + "cannot create ARP responder flow for interface name {}, vpnName {}", subnetId, interfaceName, vpnName);
                gwMac = InterfaceUtils.getMacAddressFromInterfaceState(interfaceState);
            }
            LOG.info("processVpnInterfaceAdjacencies: Added prefix {} to interface {} with nextHops {} on dpn {}" + " for vpn {}", prefix, interfaceName, nhList, dpnId, vpnName);
        } else {
            // Extra route adjacency
            String prefix = VpnUtil.getIpPrefix(nextHop.getIpAddress());
            String vpnPrefixKey = VpnUtil.getVpnNamePrefixKey(vpnName, prefix);
            synchronized (vpnPrefixKey.intern()) {
                java.util.Optional<String> rdToAllocate = VpnUtil.allocateRdForExtraRouteAndUpdateUsedRdsMap(dataBroker, vpnId, null, prefix, vpnName, nextHop.getNextHopIpList().get(0), dpnId);
                if (rdToAllocate.isPresent()) {
                    rd = rdToAllocate.get();
                    LOG.info("processVpnInterfaceAdjacencies: The rd {} is allocated for the extraroute {}", rd, prefix);
                } else {
                    LOG.error("processVpnInterfaceAdjacencies: No rds to allocate extraroute {}", prefix);
                    continue;
                }
            }
            LOG.info("processVpnInterfaceAdjacencies: Added prefix {} and nextHopList {} as extra-route for vpn{}" + " interface {} on dpn {}", nextHop.getIpAddress(), nextHop.getNextHopIpList(), vpnName, interfaceName, dpnId);
        }
        // Please note that primary adjacency will use a subnet-gateway-mac-address that
        // can be different from the gateway-mac-address within the VRFEntry as the
        // gateway-mac-address is a superset.
        RouteOrigin origin = nextHop.getAdjacencyType() == AdjacencyType.PrimaryAdjacency ? RouteOrigin.LOCAL : RouteOrigin.STATIC;
        L3vpnInput input = new L3vpnInput().setNextHop(nextHop).setRd(rd).setVpnName(vpnName).setInterfaceName(interfaceName).setNextHopIp(nextHopIp).setPrimaryRd(primaryRd).setSubnetGatewayMacAddress(vpnInterfaceSubnetGwMacAddress).setRouteOrigin(origin);
        Adjacency operationalAdjacency = null;
        try {
            operationalAdjacency = registeredPopulator.createOperationalAdjacency(input);
        } catch (NullPointerException e) {
            LOG.error("processVpnInterfaceAdjacencies: failed to create operational adjacency: input: {}, {}", input, e.getMessage());
            return;
        }
        if (nextHop.getAdjacencyType() != AdjacencyType.PrimaryAdjacency) {
            vpnManager.addExtraRoute(vpnName, nextHop.getIpAddress(), nextHop.getNextHopIpList().get(0), rd, vpnName, l3vni, origin, interfaceName, operationalAdjacency, encapType, writeConfigTxn);
        }
        value.add(operationalAdjacency);
    }
    AdjacenciesOp aug = VpnUtil.getVpnInterfaceOpDataEntryAugmentation(value);
    addVpnInterfaceToOperational(vpnName, interfaceName, dpnId, aug, lportTag, gwMac.isPresent() ? gwMac.get() : null, writeOperTxn);
    L3vpnInput input = new L3vpnInput().setNextHopIp(nextHopIp).setL3vni(l3vni).setPrimaryRd(primaryRd).setGatewayMac(gwMac.orNull()).setInterfaceName(interfaceName).setVpnName(vpnName).setDpnId(dpnId).setEncapType(encapType);
    for (Adjacency nextHop : aug.getAdjacency()) {
        // Adjacencies other than primary Adjacencies are handled in the addExtraRoute call above.
        if (nextHop.getAdjacencyType() == AdjacencyType.PrimaryAdjacency) {
            RouteOrigin origin = nextHop.getAdjacencyType() == AdjacencyType.PrimaryAdjacency ? RouteOrigin.LOCAL : RouteOrigin.STATIC;
            input.setNextHop(nextHop).setRd(nextHop.getVrfId()).setRouteOrigin(origin);
            registeredPopulator.populateFib(input, writeConfigTxn);
        }
    }
}
Also used : ArrayList(java.util.ArrayList) VpnPopulator(org.opendaylight.netvirt.vpnmanager.populator.intfc.VpnPopulator) Adjacency(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.adjacency.list.Adjacency) RouteOrigin(org.opendaylight.netvirt.fibmanager.api.RouteOrigin) Prefixes(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.prefix.to._interface.vpn.ids.Prefixes) Adjacencies(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.Adjacencies) ExecutionException(java.util.concurrent.ExecutionException) VrfEntry(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.vrfentries.VrfEntry) VpnInstanceOpDataEntry(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.instance.op.data.VpnInstanceOpDataEntry) Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) VpnInterface(org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.interfaces.VpnInterface) AdjacenciesOp(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.AdjacenciesOp) L3vpnInput(org.opendaylight.netvirt.vpnmanager.populator.input.L3vpnInput)

Example 7 with AdjacenciesOp

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.AdjacenciesOp in project netvirt by opendaylight.

the class VpnInterfaceManager method advertiseAdjacenciesForVpnToBgp.

// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
private void advertiseAdjacenciesForVpnToBgp(final String rd, BigInteger dpnId, final InstanceIdentifier<VpnInterfaceOpDataEntry> identifier, String vpnName, String interfaceName) {
    if (rd == null) {
        LOG.error("advertiseAdjacenciesForVpnFromBgp: Unable to recover rd for interface {} on dpn {} in vpn {}", interfaceName, dpnId, vpnName);
        return;
    } else {
        if (rd.equals(vpnName)) {
            LOG.info("advertiseAdjacenciesForVpnFromBgp: Ignoring BGP advertisement for interface {} on dpn {}" + " as it is in internal vpn{} with rd {}", interfaceName, dpnId, vpnName, rd);
            return;
        }
    }
    LOG.info("advertiseAdjacenciesForVpnToBgp: Advertising interface {} on dpn {} in vpn {} with rd {} ", interfaceName, dpnId, vpnName, rd);
    String nextHopIp = InterfaceUtils.getEndpointIpAddressForDPN(dataBroker, dpnId);
    if (nextHopIp == null) {
        LOG.error("advertiseAdjacenciesForVpnToBgp: NextHop for interface {} on dpn {} is null," + " returning from advertising route with rd {} vpn {} to bgp", interfaceName, dpnId, rd, vpnName);
        return;
    }
    // Read NextHops
    InstanceIdentifier<AdjacenciesOp> path = identifier.augmentation(AdjacenciesOp.class);
    Optional<AdjacenciesOp> adjacencies = VpnUtil.read(dataBroker, LogicalDatastoreType.OPERATIONAL, path);
    if (adjacencies.isPresent()) {
        List<Adjacency> nextHops = adjacencies.get().getAdjacency();
        if (!nextHops.isEmpty()) {
            LOG.debug("advertiseAdjacenciesForVpnToBgp:  NextHops are {} for interface {} on dpn {} for vpn {}" + " rd {}", nextHops, interfaceName, dpnId, vpnName, rd);
            VpnInstanceOpDataEntry vpnInstanceOpData = VpnUtil.getVpnInstanceOpData(dataBroker, rd);
            long l3vni = vpnInstanceOpData.getL3vni();
            VrfEntry.EncapType encapType = VpnUtil.isL3VpnOverVxLan(l3vni) ? VrfEntry.EncapType.Vxlan : VrfEntry.EncapType.Mplsgre;
            for (Adjacency nextHop : nextHops) {
                if (nextHop.getAdjacencyType() == AdjacencyType.ExtraRoute) {
                    continue;
                }
                String gatewayMac = null;
                long label = 0;
                if (VpnUtil.isL3VpnOverVxLan(l3vni)) {
                    final VpnPortipToPort gwPort = VpnUtil.getNeutronPortFromVpnPortFixedIp(dataBroker, vpnInstanceOpData.getVpnInstanceName(), nextHop.getIpAddress());
                    gatewayMac = arpResponderHandler.getGatewayMacAddressForInterface(gwPort, interfaceName).get();
                } else {
                    label = nextHop.getLabel();
                }
                try {
                    LOG.info("VPN ADVERTISE: advertiseAdjacenciesForVpnToBgp: Adding Fib Entry rd {} prefix {}" + " nexthop {} label {}", rd, nextHop.getIpAddress(), nextHopIp, label);
                    bgpManager.advertisePrefix(rd, nextHop.getMacAddress(), nextHop.getIpAddress(), nextHopIp, encapType, (int) label, l3vni, 0, /*l2vni*/
                    gatewayMac);
                    LOG.info("VPN ADVERTISE: advertiseAdjacenciesForVpnToBgp: Added Fib Entry rd {} prefix {}" + " nexthop {} label {} for interface {} on dpn {} for vpn {}", rd, nextHop.getIpAddress(), nextHopIp, label, interfaceName, dpnId, vpnName);
                } catch (Exception e) {
                    LOG.error("advertiseAdjacenciesForVpnToBgp: Failed to advertise prefix {} in vpn {} with rd {}" + " for interface {} on dpn {}", nextHop.getIpAddress(), vpnName, rd, interfaceName, dpnId, e);
                }
            }
        }
    }
}
Also used : VrfEntry(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.vrfentries.VrfEntry) VpnInstanceOpDataEntry(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.instance.op.data.VpnInstanceOpDataEntry) VpnPortipToPort(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.neutron.vpn.portip.port.data.VpnPortipToPort) AdjacenciesOp(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.AdjacenciesOp) Adjacency(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.adjacency.list.Adjacency) ExecutionException(java.util.concurrent.ExecutionException)

Example 8 with AdjacenciesOp

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.AdjacenciesOp in project netvirt by opendaylight.

the class VpnInterfaceManager method withdrawAdjacenciesForVpnFromBgp.

// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
private void withdrawAdjacenciesForVpnFromBgp(final InstanceIdentifier<VpnInterfaceOpDataEntry> identifier, String vpnName, String interfaceName, WriteTransaction writeConfigTxn) {
    // Read NextHops
    InstanceIdentifier<AdjacenciesOp> path = identifier.augmentation(AdjacenciesOp.class);
    Optional<AdjacenciesOp> adjacencies = VpnUtil.read(dataBroker, LogicalDatastoreType.OPERATIONAL, path);
    String rd = VpnUtil.getVpnRd(dataBroker, interfaceName);
    if (rd == null) {
        LOG.error("withdrawAdjacenciesForVpnFromBgp: Unable to recover rd for interface {} in vpn {}", interfaceName, vpnName);
        return;
    } else {
        if (rd.equals(vpnName)) {
            LOG.info("withdrawAdjacenciesForVpnFromBgp: Ignoring BGP withdrawal for interface {} as it is in " + "internal vpn{} with rd {}", interfaceName, vpnName, rd);
            return;
        }
    }
    LOG.info("withdrawAdjacenciesForVpnFromBgp: For interface {} in vpn {} with rd {}", interfaceName, vpnName, rd);
    if (adjacencies.isPresent()) {
        List<Adjacency> nextHops = adjacencies.get().getAdjacency();
        if (!nextHops.isEmpty()) {
            LOG.trace("withdrawAdjacenciesForVpnFromBgp: NextHops are {} for interface {} in vpn {} rd {}", nextHops, interfaceName, vpnName, rd);
            for (Adjacency nextHop : nextHops) {
                try {
                    if (nextHop.getAdjacencyType() != AdjacencyType.ExtraRoute) {
                        LOG.info("VPN WITHDRAW: withdrawAdjacenciesForVpnFromBgp: Removing Fib Entry rd {}" + " prefix {} for interface {} in vpn {}", rd, nextHop.getIpAddress(), interfaceName, vpnName);
                        bgpManager.withdrawPrefix(rd, nextHop.getIpAddress());
                        LOG.info("VPN WITHDRAW: withdrawAdjacenciesForVpnFromBgp: Removed Fib Entry rd {}" + " prefix {} for interface {} in vpn {}", rd, nextHop.getIpAddress(), interfaceName, vpnName);
                    } else {
                        // Perform similar operation as interface delete event for extraroutes.
                        String allocatedRd = nextHop.getVrfId();
                        for (String nh : nextHop.getNextHopIpList()) {
                            deleteExtraRouteFromCurrentAndImportingVpns(vpnName, nextHop.getIpAddress(), nh, allocatedRd, interfaceName, writeConfigTxn);
                        }
                    }
                } catch (Exception e) {
                    LOG.error("withdrawAdjacenciesForVpnFromBgp: Failed to withdraw prefix {} in vpn {} with rd {}" + " for interface {} ", nextHop.getIpAddress(), vpnName, rd, interfaceName, e);
                }
            }
        }
    }
}
Also used : AdjacenciesOp(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.AdjacenciesOp) Adjacency(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.adjacency.list.Adjacency) ExecutionException(java.util.concurrent.ExecutionException)

Example 9 with AdjacenciesOp

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.AdjacenciesOp in project netvirt by opendaylight.

the class VpnInterfaceManager method removeAdjacenciesFromVpn.

private void removeAdjacenciesFromVpn(final BigInteger dpnId, final int lportTag, final String interfaceName, final String vpnName, final long vpnId, String gwMac, WriteTransaction writeConfigTxn, final WriteTransaction writeOperTxn, final WriteTransaction writeInvTxn) {
    // Read NextHops
    InstanceIdentifier<VpnInterfaceOpDataEntry> identifier = VpnUtil.getVpnInterfaceOpDataEntryIdentifier(interfaceName, vpnName);
    InstanceIdentifier<AdjacenciesOp> path = identifier.augmentation(AdjacenciesOp.class);
    Optional<AdjacenciesOp> adjacencies = VpnUtil.read(dataBroker, LogicalDatastoreType.OPERATIONAL, path);
    String primaryRd = VpnUtil.getVpnRd(dataBroker, vpnName);
    LOG.info("removeAdjacenciesFromVpn: For interface {} on dpn {} RD recovered for vpn {} as rd {}", interfaceName, dpnId, vpnName, primaryRd);
    if (adjacencies.isPresent() && !adjacencies.get().getAdjacency().isEmpty()) {
        List<Adjacency> nextHops = adjacencies.get().getAdjacency();
        LOG.info("removeAdjacenciesFromVpn: NextHops for interface {} on dpn {} for vpn {} are {}", interfaceName, dpnId, vpnName, nextHops);
        for (Adjacency nextHop : nextHops) {
            if (nextHop.isPhysNetworkFunc()) {
                LOG.info("removeAdjacenciesFromVpn: Removing PNF FIB entry rd {} prefix {}", nextHop.getSubnetId().getValue(), nextHop.getIpAddress());
                fibManager.removeFibEntry(nextHop.getSubnetId().getValue(), nextHop.getIpAddress(), null);
            } else {
                String rd = nextHop.getVrfId();
                List<String> nhList;
                if (nextHop.getAdjacencyType() != AdjacencyType.PrimaryAdjacency) {
                    nhList = getNextHopForNonPrimaryAdjacency(nextHop, vpnName, dpnId, interfaceName);
                } else {
                    // This is a primary adjacency
                    nhList = nextHop.getNextHopIpList() != null ? nextHop.getNextHopIpList() : Collections.emptyList();
                    removeGwMacAndArpResponderFlows(nextHop, vpnId, dpnId, lportTag, gwMac, interfaceName, writeInvTxn);
                }
                if (!nhList.isEmpty()) {
                    if (rd.equals(vpnName)) {
                        // this is an internal vpn - the rd is assigned to the vpn instance name;
                        // remove from FIB directly
                        nhList.forEach(removeAdjacencyFromInternalVpn(nextHop, vpnName, interfaceName, dpnId, writeConfigTxn));
                    } else {
                        removeAdjacencyFromBgpvpn(nextHop, nhList, vpnName, primaryRd, dpnId, rd, interfaceName, writeConfigTxn);
                    }
                } else {
                    LOG.error("removeAdjacenciesFromVpn: nextHop empty for ip {} rd {} adjacencyType {}" + " interface {}", nextHop.getIpAddress(), rd, nextHop.getAdjacencyType().toString(), interfaceName);
                    bgpManager.withdrawPrefixIfPresent(rd, nextHop.getIpAddress());
                    fibManager.removeFibEntry(primaryRd, nextHop.getIpAddress(), writeConfigTxn);
                }
            }
            String ip = nextHop.getIpAddress().split("/")[0];
            LearntVpnVipToPort vpnVipToPort = VpnUtil.getLearntVpnVipToPort(dataBroker, vpnName, ip);
            if (vpnVipToPort != null) {
                VpnUtil.removeLearntVpnVipToPort(dataBroker, vpnName, ip);
                LOG.info("removeAdjacenciesFromVpn: VpnInterfaceManager removed adjacency for Interface {}" + " ip {} on dpn {} for vpn {} from VpnPortData Entry", vpnVipToPort.getPortName(), ip, dpnId, vpnName);
            }
        }
    } else {
        // this vpn interface has no more adjacency left, so clean up the vpn interface from Operational DS
        LOG.info("removeAdjacenciesFromVpn: Vpn Interface {} on vpn {} dpn {} has no adjacencies." + " Removing it.", interfaceName, vpnName, dpnId);
        writeOperTxn.delete(LogicalDatastoreType.OPERATIONAL, identifier);
    }
}
Also used : AdjacenciesOp(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.AdjacenciesOp) Adjacency(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.adjacency.list.Adjacency) LearntVpnVipToPort(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.learnt.vpn.vip.to.port.data.LearntVpnVipToPort) VpnInterfaceOpDataEntry(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn._interface.op.data.VpnInterfaceOpDataEntry)

Example 10 with AdjacenciesOp

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.AdjacenciesOp in project netvirt by opendaylight.

the class VpnInterfaceOpListener method postProcessVpnInterfaceRemoval.

private void postProcessVpnInterfaceRemoval(InstanceIdentifier<VpnInterfaceOpDataEntry> identifier, VpnInterfaceOpDataEntry del, WriteTransaction writeOperTxn) {
    final VpnInterfaceOpDataEntryKey key = identifier.firstKeyOf(VpnInterfaceOpDataEntry.class, VpnInterfaceOpDataEntryKey.class);
    String interfaceName = key.getName();
    String vpnName = del.getVpnInstanceName();
    LOG.info("postProcessVpnInterfaceRemoval: interface name {} vpnName {} dpn {}", interfaceName, vpnName, del.getDpnId());
    // decrement the vpn interface count in Vpn Instance Op Data
    Optional<VpnInstance> vpnInstance = VpnUtil.read(dataBroker, LogicalDatastoreType.CONFIGURATION, VpnOperDsUtils.getVpnInstanceToVpnIdIdentifier(vpnName));
    if (vpnInstance.isPresent()) {
        String rd = null;
        rd = vpnInstance.get().getVrfId();
        VpnInstanceOpDataEntry vpnInstOp = VpnUtil.getVpnInstanceOpData(dataBroker, rd);
        AdjacenciesOp adjs = del.getAugmentation(AdjacenciesOp.class);
        List<Adjacency> adjList = adjs != null ? adjs.getAdjacency() : null;
        if (vpnInstOp != null && adjList != null && adjList.size() > 0) {
            /*
                 * When a VPN Interface is removed by FibManager (aka VrfEntryListener and its cohorts),
                 * one adjacency for that VPN Interface will be hanging around along with that
                 * VPN Interface.   That adjacency could be primary (or) non-primary.
                 * If its a primary adjacency, then a prefix-to-interface entry will be available for the
                 * same.  If its a non-primary adjacency, then a prefix-to-interface entry will not be
                 * available for the same, instead we will have vpn-to-extraroutes filled in for them.
                 *
                 * Here we try to remove prefix-to-interface entry for pending adjacency in the deleted
                 * vpnInterface.   More importantly, we also update the vpnInstanceOpData by removing this
                 * vpnInterface from it.
                 */
            List<Prefixes> prefixToInterface = new ArrayList<>();
            for (Adjacency adjacency : adjs.getAdjacency()) {
                List<Prefixes> prefixToInterfaceLocal = new ArrayList<>();
                Optional<Prefixes> prefix = VpnUtil.read(dataBroker, LogicalDatastoreType.OPERATIONAL, VpnUtil.getPrefixToInterfaceIdentifier(vpnInstOp.getVpnId(), VpnUtil.getIpPrefix(adjacency.getIpAddress())));
                if (prefix.isPresent()) {
                    prefixToInterfaceLocal.add(prefix.get());
                }
                if (prefixToInterfaceLocal.isEmpty()) {
                    for (String nh : adjacency.getNextHopIpList()) {
                        prefix = VpnUtil.read(dataBroker, LogicalDatastoreType.OPERATIONAL, VpnUtil.getPrefixToInterfaceIdentifier(vpnInstOp.getVpnId(), VpnUtil.getIpPrefix(nh)));
                        if (prefix.isPresent()) {
                            prefixToInterfaceLocal.add(prefix.get());
                        }
                    }
                }
                if (!prefixToInterfaceLocal.isEmpty()) {
                    prefixToInterface.addAll(prefixToInterfaceLocal);
                }
            }
            /*
                 * In VPN Migration scenarios, there is a race condition where we use the new DPNID
                 * for the migrated VM instead of old DPNID because when we read prefix-to-interface to cleanup
                 * old DPNID, we actually get the new DPNID.
                 *
                 * More dangerously, we tend to alter the new prefix-to-interface which should be retained intac
                 * for the migration to succeed in L3VPN.  As a workaround, here we are going to use the dpnId in
                 * the deleted vpnInterface itself instead of tinkering with the prefix-to-interface.  Further we
                 * will tinker prefix-to-interface only when are damn sure if its value matches our
                 * deleted vpnInterface.
                 *
                 */
            for (Prefixes pref : prefixToInterface) {
                if (isMatchedPrefixToInterface(pref, del)) {
                    if (writeOperTxn != null) {
                        writeOperTxn.delete(LogicalDatastoreType.OPERATIONAL, VpnUtil.getPrefixToInterfaceIdentifier(vpnInstOp.getVpnId(), pref.getIpAddress()));
                    } else {
                        VpnUtil.delete(dataBroker, LogicalDatastoreType.OPERATIONAL, VpnUtil.getPrefixToInterfaceIdentifier(vpnInstOp.getVpnId(), pref.getIpAddress()), VpnUtil.DEFAULT_CALLBACK);
                    }
                }
            }
        }
        if (del.getDpnId() != null) {
            vpnFootprintService.updateVpnToDpnMapping(del.getDpnId(), del.getVpnInstanceName(), rd, interfaceName, null, /*ipAddressSourceValuePair*/
            false);
        }
        LOG.info("postProcessVpnInterfaceRemoval: Removed vpn operational data and updated vpn footprint" + " for interface {} on dpn {} vpn {}", interfaceName, del.getDpnId(), vpnName);
    } else {
        LOG.error("postProcessVpnInterfaceRemoval: rd not retrievable as vpninstancetovpnid for vpn {} is absent," + " trying rd as {}. interface {} dpn {}", vpnName, vpnName, interfaceName, del.getDpnId());
    }
    notifyTaskIfRequired(interfaceName);
}
Also used : VpnInstanceOpDataEntry(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.instance.op.data.VpnInstanceOpDataEntry) VpnInterfaceOpDataEntryKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn._interface.op.data.VpnInterfaceOpDataEntryKey) AdjacenciesOp(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.AdjacenciesOp) VpnInstance(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.instance.to.vpn.id.VpnInstance) ArrayList(java.util.ArrayList) Adjacency(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.adjacency.list.Adjacency) Prefixes(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.prefix.to._interface.vpn.ids.Prefixes)

Aggregations

AdjacenciesOp (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.AdjacenciesOp)11 Adjacency (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.adjacency.list.Adjacency)11 VpnInterfaceOpDataEntry (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn._interface.op.data.VpnInterfaceOpDataEntry)8 ArrayList (java.util.ArrayList)6 VpnInstanceOpDataEntry (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.instance.op.data.VpnInstanceOpDataEntry)6 ExecutionException (java.util.concurrent.ExecutionException)5 VrfEntry (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.vrfentries.VrfEntry)5 VpnInterfaceOpDataEntryKey (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn._interface.op.data.VpnInterfaceOpDataEntryKey)4 BigInteger (java.math.BigInteger)3 AdjacencyBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.adjacency.list.AdjacencyBuilder)3 VpnInterfaceOpDataEntryBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn._interface.op.data.VpnInterfaceOpDataEntryBuilder)3 List (java.util.List)2 RouteOrigin (org.opendaylight.netvirt.fibmanager.api.RouteOrigin)2 L3vpnInput (org.opendaylight.netvirt.vpnmanager.populator.input.L3vpnInput)2 VpnPopulator (org.opendaylight.netvirt.vpnmanager.populator.intfc.VpnPopulator)2 VpnInterface (org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.interfaces.VpnInterface)2 VpnInstanceNames (org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.interfaces.vpn._interface.VpnInstanceNames)2 Uuid (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid)2 Adjacencies (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.Adjacencies)2 Prefixes (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.prefix.to._interface.vpn.ids.Prefixes)2