Search in sources :

Example 26 with AdjacencyKey

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.adjacency.list.AdjacencyKey in project netvirt by opendaylight.

the class NeutronvpnManager method getAdjacencyforExtraRoute.

@NonNull
protected List<Adjacency> getAdjacencyforExtraRoute(List<Routes> routeList, String fixedIp) {
    List<Adjacency> adjList = new ArrayList<>();
    Map<String, List<String>> adjMap = new HashMap<>();
    for (Routes route : routeList) {
        if (route == null || route.getNexthop() == null || route.getDestination() == null) {
            LOG.error("Incorrect input received for extra route. {}", route);
        } else {
            String nextHop = route.getNexthop().stringValue();
            String destination = route.getDestination().stringValue();
            if (!nextHop.equals(fixedIp)) {
                LOG.trace("FixedIP {} is not extra route nexthop for destination {}", fixedIp, destination);
                continue;
            }
            LOG.trace("Adding extra route for destination {} with nexthop {} ", destination, nextHop);
            List<String> hops = adjMap.computeIfAbsent(destination, k -> new ArrayList<>());
            if (!hops.contains(nextHop)) {
                hops.add(nextHop);
            }
        }
    }
    for (Entry<String, List<String>> entry : adjMap.entrySet()) {
        final String destination = entry.getKey();
        final List<String> ipList = entry.getValue();
        Adjacency erAdj = new AdjacencyBuilder().setIpAddress(destination).setAdjacencyType(AdjacencyType.ExtraRoute).setNextHopIpList(ipList).withKey(new AdjacencyKey(destination)).build();
        adjList.add(erAdj);
    }
    return adjList;
}
Also used : AdjacencyBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.adjacency.list.AdjacencyBuilder) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) AdjacencyKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.adjacency.list.AdjacencyKey) ArrayList(java.util.ArrayList) Routes(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l3.rev150712.l3.attributes.Routes) Adjacency(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.adjacency.list.Adjacency) Collections.singletonList(java.util.Collections.singletonList) ArrayList(java.util.ArrayList) List(java.util.List) NonNull(org.eclipse.jdt.annotation.NonNull)

Example 27 with AdjacencyKey

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.adjacency.list.AdjacencyKey in project netvirt by opendaylight.

the class NeutronvpnManager method withdrawPortIpFromVpnIface.

protected void withdrawPortIpFromVpnIface(Uuid vpnId, Uuid internetVpnId, Port port, Subnetmap sn, TypedWriteTransaction<Configuration> wrtConfigTxn) {
    String infName = port.getUuid().getValue();
    InstanceIdentifier<VpnInterface> vpnIfIdentifier = NeutronvpnUtils.buildVpnInterfaceIdentifier(infName);
    Optional<VpnInterface> optionalVpnInterface = null;
    LOG.debug("withdrawPortIpFromVpnIface vpn {} internetVpn {} Port {}", vpnId, internetVpnId, infName);
    try {
        optionalVpnInterface = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, vpnIfIdentifier);
    } catch (ExecutionException | InterruptedException e) {
        LOG.error("withdrawPortIpFromVpnIface: Error reading the VPN interface for {}", vpnIfIdentifier, e);
        return;
    }
    if (!optionalVpnInterface.isPresent()) {
        return;
    }
    LOG.trace("withdraw adjacencies for Port: {} subnet {}", port.getUuid().getValue(), sn != null ? sn.getSubnetIp() : "null");
    Map<AdjacencyKey, Adjacency> keyAdjacencyMap = optionalVpnInterface.get().augmentation(Adjacencies.class).nonnullAdjacency();
    List<Adjacency> updatedAdjsList = new ArrayList<>();
    boolean isIpFromAnotherSubnet = false;
    for (Adjacency adj : keyAdjacencyMap.values()) {
        String adjString = FibHelper.getIpFromPrefix(adj.getIpAddress());
        if (sn == null || !Objects.equals(adj.getSubnetId(), sn.getId())) {
            if (adj.getAdjacencyType() == AdjacencyType.PrimaryAdjacency) {
                isIpFromAnotherSubnet = true;
            }
            updatedAdjsList.add(adj);
            continue;
        }
        if (adj.getAdjacencyType() == AdjacencyType.PrimaryAdjacency) {
            LOG.error("withdrawPortIpFromVpnIface: suppressing primaryAdjacency {} FixedIp for vpnId {}", adjString, vpnId);
            if (vpnId != null) {
                neutronvpnUtils.removeVpnPortFixedIpToPort(vpnId.getValue(), String.valueOf(adjString), wrtConfigTxn);
            }
            if (internetVpnId != null) {
                neutronvpnUtils.removeVpnPortFixedIpToPort(internetVpnId.getValue(), String.valueOf(adjString), wrtConfigTxn);
            }
        } else {
            if (NeutronConstants.DEVICE_OWNER_ROUTER_INF.equals(port.getDeviceOwner()) && sn.getRouterId() != null) {
                Router rtr = neutronvpnUtils.getNeutronRouter(sn.getRouterId());
                if (rtr != null && rtr.getRoutes() != null) {
                    List<Routes> extraRoutesToRemove = new ArrayList<>();
                    for (Routes rt : rtr.getRoutes().values()) {
                        if (rt.getNexthop().toString().equals(adjString)) {
                            extraRoutesToRemove.add(rt);
                        }
                    }
                    if (vpnId != null) {
                        LOG.error("withdrawPortIpFromVpnIface: suppressing extraRoute {} for vpnId {}", extraRoutesToRemove, vpnId);
                        removeAdjacencyforExtraRoute(vpnId, extraRoutesToRemove);
                    }
                /* removeAdjacencyforExtraRoute done also for internet-vpn-id, in previous call */
                }
            }
        }
    }
    Adjacencies adjacencies = new AdjacenciesBuilder().setAdjacency(getAdjacencyMap(updatedAdjsList)).build();
    if (vpnId != null) {
        updateVpnInterfaceWithAdjacencies(vpnId, infName, adjacencies, wrtConfigTxn);
    }
    if (!isIpFromAnotherSubnet) {
        // no more subnetworks for neutron port
        if (sn != null && sn.getRouterId() != null) {
            removeFromNeutronRouterInterfacesMap(sn.getRouterId(), port.getUuid().getValue());
        }
        deleteVpnInterface(infName, null, /* vpn-id */
        wrtConfigTxn);
        return;
    }
    return;
}
Also used : AdjacencyKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.adjacency.list.AdjacencyKey) ArrayList(java.util.ArrayList) Router(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l3.rev150712.routers.attributes.routers.Router) Routes(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l3.rev150712.l3.attributes.Routes) Adjacencies(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.Adjacencies) VpnInterface(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.vpn.interfaces.VpnInterface) AdjacenciesBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.AdjacenciesBuilder) Adjacency(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.adjacency.list.Adjacency) ExecutionException(java.util.concurrent.ExecutionException)

Example 28 with AdjacencyKey

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.adjacency.list.AdjacencyKey in project netvirt by opendaylight.

the class NeutronvpnManager method updateVpnInterface.

protected void updateVpnInterface(Uuid vpnId, @Nullable Uuid oldVpnId, Port port, boolean isBeingAssociated, boolean isSubnetIp, TypedWriteTransaction<Configuration> writeConfigTxn, boolean isInternetVpn) {
    if (vpnId == null || port == null) {
        return;
    }
    String infName = port.getUuid().getValue();
    InstanceIdentifier<VpnInterface> vpnIfIdentifier = NeutronvpnUtils.buildVpnInterfaceIdentifier(infName);
    try (AcquireResult lock = tryInterfaceLock(infName)) {
        if (!lock.wasAcquired()) {
            // FIXME: why do we even bother with locking if we do not honor it?!
            logTryLockFailure(infName);
        }
        try {
            Optional<VpnInterface> optionalVpnInterface = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, vpnIfIdentifier);
            if (optionalVpnInterface.isPresent()) {
                VpnInstanceNames vpnInstance = VpnHelper.getVpnInterfaceVpnInstanceNames(vpnId.getValue(), AssociatedSubnetType.V4AndV6Subnets);
                List<VpnInstanceNames> listVpn = new ArrayList<>(optionalVpnInterface.get().getVpnInstanceNames().values());
                if (oldVpnId != null && VpnHelper.doesVpnInterfaceBelongToVpnInstance(oldVpnId.getValue(), listVpn)) {
                    VpnHelper.removeVpnInterfaceVpnInstanceNamesFromList(oldVpnId.getValue(), listVpn);
                }
                if (vpnId.getValue() != null && !VpnHelper.doesVpnInterfaceBelongToVpnInstance(vpnId.getValue(), listVpn)) {
                    listVpn.add(vpnInstance);
                }
                VpnInterfaceBuilder vpnIfBuilder = new VpnInterfaceBuilder(optionalVpnInterface.get()).setVpnInstanceNames(listVpn);
                LOG.debug("Updating vpn interface {}", infName);
                if (!isBeingAssociated) {
                    Adjacencies adjs = vpnIfBuilder.augmentation(Adjacencies.class);
                    Map<AdjacencyKey, Adjacency> keyAdjacencyMap = adjs != null ? adjs.getAdjacency() : new HashMap<>();
                    Iterator<Adjacency> adjacencyIter = keyAdjacencyMap.values().iterator();
                    while (adjacencyIter.hasNext()) {
                        Adjacency adjacency = adjacencyIter.next();
                        String mipToQuery = adjacency.getIpAddress().split("/")[0];
                        InstanceIdentifier<LearntVpnVipToPort> id = NeutronvpnUtils.buildLearntVpnVipToPortIdentifier(oldVpnId.getValue(), mipToQuery);
                        Optional<LearntVpnVipToPort> optionalVpnVipToPort = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.OPERATIONAL, id);
                        if (optionalVpnVipToPort.isPresent() && optionalVpnVipToPort.get().getPortName().equals(infName)) {
                            LOG.trace("Removing adjacencies from vpninterface {} upon dissociation of router {} " + "from VPN {}", infName, vpnId, oldVpnId);
                            adjacencyIter.remove();
                            neutronvpnUtils.removeLearntVpnVipToPort(oldVpnId.getValue(), mipToQuery);
                            LOG.trace("Entry for fixedIP {} for port {} on VPN {} removed from LearntVpnVipToPort", mipToQuery, infName, vpnId.getValue());
                        }
                        InstanceIdentifier<VpnPortipToPort> build = NeutronvpnUtils.buildVpnPortipToPortIdentifier(oldVpnId.getValue(), mipToQuery);
                        Optional<VpnPortipToPort> persistedIp = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.OPERATIONAL, build);
                        if (persistedIp.isPresent() && persistedIp.get().getPortName().equals(infName)) {
                            neutronvpnUtils.removeVpnPortFixedIpToPort(oldVpnId.getValue(), mipToQuery, null);
                            LOG.trace("Entry for fixedIP {} for port {} on VPN {} removed from VpnPortipToPort", mipToQuery, infName, vpnId.getValue());
                        }
                    }
                    Adjacencies adjacencies = new AdjacenciesBuilder().setAdjacency(keyAdjacencyMap).build();
                    vpnIfBuilder.addAugmentation(adjacencies);
                }
                for (FixedIps ip : port.nonnullFixedIps().values()) {
                    String ipValue = ip.getIpAddress().stringValue();
                    if (oldVpnId != null) {
                        neutronvpnUtils.removeVpnPortFixedIpToPort(oldVpnId.getValue(), ipValue, writeConfigTxn);
                    }
                    if (NeutronvpnUtils.getIpVersionFromString(ipValue) != IpVersionChoice.IPV6 && isInternetVpn == true) {
                        continue;
                    }
                    neutronvpnUtils.createVpnPortFixedIpToPort(vpnId.getValue(), ipValue, infName, port.getMacAddress().getValue(), isSubnetIp, writeConfigTxn);
                }
                writeConfigTxn.put(vpnIfIdentifier, vpnIfBuilder.build());
            } else {
                LOG.error("VPN Interface {} not found", infName);
            }
        } catch (ExecutionException | InterruptedException ex) {
            LOG.error("Updation of vpninterface {} failed", infName, ex);
        }
    }
}
Also used : VpnPortipToPort(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.neutron.vpn.portip.port.data.VpnPortipToPort) ArrayList(java.util.ArrayList) Adjacency(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.adjacency.list.Adjacency) LearntVpnVipToPort(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.learnt.vpn.vip.to.port.data.LearntVpnVipToPort) ExecutionException(java.util.concurrent.ExecutionException) VpnInterfaceBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.vpn.interfaces.VpnInterfaceBuilder) AdjacencyKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.adjacency.list.AdjacencyKey) AcquireResult(org.opendaylight.infrautils.utils.concurrent.NamedSimpleReentrantLock.AcquireResult) Adjacencies(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.Adjacencies) VpnInterface(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.vpn.interfaces.VpnInterface) VpnInstanceNames(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.vpn.interfaces.vpn._interface.VpnInstanceNames) AdjacenciesBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.AdjacenciesBuilder) FixedIps(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.port.attributes.FixedIps)

Aggregations

Adjacency (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.adjacency.list.Adjacency)24 AdjacencyKey (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.adjacency.list.AdjacencyKey)24 ExecutionException (java.util.concurrent.ExecutionException)17 ArrayList (java.util.ArrayList)12 Adjacencies (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.Adjacencies)11 AdjacenciesOp (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.AdjacenciesOp)10 VpnInterface (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.vpn.interfaces.VpnInterface)10 TransactionCommitFailedException (org.opendaylight.mdsal.common.api.TransactionCommitFailedException)8 VpnInterfaceOpDataEntry (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn._interface.op.data.VpnInterfaceOpDataEntry)8 Uuid (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid)7 AdjacencyBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.adjacency.list.AdjacencyBuilder)7 Uint32 (org.opendaylight.yangtools.yang.common.Uint32)7 LearntVpnVipToPort (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.learnt.vpn.vip.to.port.data.LearntVpnVipToPort)6 VrfEntry (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.vrfentries.VrfEntry)4 Adjacency (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.adjacency.list.Adjacency)4 AdjacencyKey (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.adjacency.list.AdjacencyKey)4 VpnInstanceOpDataEntry (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.instance.op.data.VpnInstanceOpDataEntry)4 VpnInterfaceKey (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.vpn.interfaces.VpnInterfaceKey)4 Routes (org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l3.rev150712.l3.attributes.Routes)4 HashMap (java.util.HashMap)3