Search in sources :

Example 46 with Subnetmap

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.Subnetmap in project netvirt by opendaylight.

the class NeutronvpnManager method withdrawPortIpFromVpnIface.

protected void withdrawPortIpFromVpnIface(Uuid vpnId, Uuid internetVpnId, Port port, Subnetmap sn, WriteTransaction 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 (ReadFailedException 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");
    List<Adjacency> vpnAdjsList = optionalVpnInterface.get().getAugmentation(Adjacencies.class).getAdjacency();
    List<Adjacency> updatedAdjsList = new ArrayList<>();
    boolean isIpFromAnotherSubnet = false;
    for (Adjacency adj : vpnAdjsList) {
        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 (port.getDeviceOwner().equals(NeutronConstants.DEVICE_OWNER_ROUTER_INF) && 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()) {
                        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(updatedAdjsList).build();
    if (vpnId != null) {
        updateVpnInterfaceWithAdjacencies(vpnId, infName, adjacencies, wrtConfigTxn);
    }
    if (internetVpnId != null) {
        updateVpnInterfaceWithAdjacencies(internetVpnId, 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 : ReadFailedException(org.opendaylight.controller.md.sal.common.api.data.ReadFailedException) 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.l3vpn.rev130911.Adjacencies) VpnInterface(org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.interfaces.VpnInterface) AdjacenciesBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.AdjacenciesBuilder) Adjacency(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.adjacency.list.Adjacency)

Example 47 with Subnetmap

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.Subnetmap in project netvirt by opendaylight.

the class NeutronvpnManager method updateSubnetNode.

protected Subnetmap updateSubnetNode(Uuid subnetId, Uuid routerId, Uuid vpnId, Uuid internetvpnId) {
    Subnetmap subnetmap = null;
    SubnetmapBuilder builder = null;
    InstanceIdentifier<Subnetmap> id = InstanceIdentifier.builder(Subnetmaps.class).child(Subnetmap.class, new SubnetmapKey(subnetId)).build();
    try {
        synchronized (subnetId.getValue().intern()) {
            Optional<Subnetmap> sn = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, id);
            if (sn.isPresent()) {
                builder = new SubnetmapBuilder(sn.get());
                LOG.debug("updating existing subnetmap node for subnet ID {}", subnetId.getValue());
            } else {
                LOG.error("subnetmap node for subnet {} does not exist, returning", subnetId.getValue());
                return null;
            }
            if (routerId != null) {
                builder.setRouterId(routerId);
            }
            if (vpnId != null) {
                builder.setVpnId(vpnId);
            }
            builder.setInternetVpnId(internetvpnId);
            subnetmap = builder.build();
            LOG.debug("Creating/Updating subnetMap node: {} ", subnetId.getValue());
            SingleTransactionDataBroker.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, id, subnetmap);
        }
    } catch (ReadFailedException | TransactionCommitFailedException e) {
        LOG.error("Subnet map update failed for node {}", subnetId.getValue(), e);
    }
    return subnetmap;
}
Also used : ReadFailedException(org.opendaylight.controller.md.sal.common.api.data.ReadFailedException) TransactionCommitFailedException(org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException) SubnetmapKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.SubnetmapKey) Subnetmap(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.Subnetmap) SubnetmapBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.SubnetmapBuilder)

Example 48 with Subnetmap

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.Subnetmap in project netvirt by opendaylight.

the class NeutronvpnManager method removePortsFromSubnetmapNode.

protected Subnetmap removePortsFromSubnetmapNode(Uuid subnetId, Uuid portId, Uuid directPortId) {
    Subnetmap subnetmap = null;
    InstanceIdentifier<Subnetmap> id = InstanceIdentifier.builder(Subnetmaps.class).child(Subnetmap.class, new SubnetmapKey(subnetId)).build();
    try {
        synchronized (subnetId.getValue().intern()) {
            Optional<Subnetmap> sn = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, id);
            if (sn.isPresent()) {
                SubnetmapBuilder builder = new SubnetmapBuilder(sn.get());
                if (null != portId && null != builder.getPortList()) {
                    List<Uuid> portList = builder.getPortList();
                    portList.remove(portId);
                    builder.setPortList(portList);
                    LOG.debug("Removing port {} from existing subnetmap node: {} ", portId.getValue(), subnetId.getValue());
                }
                if (null != directPortId && null != builder.getDirectPortList()) {
                    List<Uuid> directPortList = builder.getDirectPortList();
                    directPortList.remove(directPortId);
                    builder.setDirectPortList(directPortList);
                    LOG.debug("Removing direct port {} from existing subnetmap node: {} ", directPortId.getValue(), subnetId.getValue());
                }
                subnetmap = builder.build();
                SingleTransactionDataBroker.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, id, subnetmap);
            } else {
                LOG.info("Trying to remove port from non-existing subnetmap node {}", subnetId.getValue());
            }
        }
    } catch (ReadFailedException | TransactionCommitFailedException e) {
        LOG.error("Removing a port from port list of a subnetmap failed for node: {}", subnetId.getValue(), e);
    }
    return subnetmap;
}
Also used : ReadFailedException(org.opendaylight.controller.md.sal.common.api.data.ReadFailedException) TransactionCommitFailedException(org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException) Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) SubnetmapKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.SubnetmapKey) Subnetmap(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.Subnetmap) SubnetmapBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.SubnetmapBuilder)

Example 49 with Subnetmap

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.Subnetmap in project netvirt by opendaylight.

the class NeutronvpnManager method dissociateRouterFromVpn.

// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
protected void dissociateRouterFromVpn(Uuid vpnId, Uuid routerId) {
    List<Uuid> routerSubnets = neutronvpnUtils.getNeutronRouterSubnetIds(routerId);
    boolean vpnInstanceIpVersionsRemoved = false;
    IpVersionChoice vpnInstanceIpVersionsToRemove = IpVersionChoice.UNDEFINED;
    for (Uuid subnetId : routerSubnets) {
        Subnetmap sn = neutronvpnUtils.getSubnetmap(subnetId);
        if (neutronvpnUtils.shouldVpnHandleIpVersionChangeToRemove(sn, vpnId)) {
            vpnInstanceIpVersionsToRemove = vpnInstanceIpVersionsToRemove.addVersion(NeutronvpnUtils.getIpVersionFromString(sn.getSubnetIp()));
            vpnInstanceIpVersionsRemoved = true;
        }
        LOG.debug("Updating association of subnets to internal vpn {}", routerId.getValue());
        updateVpnForSubnet(vpnId, routerId, subnetId, false);
    }
    if (vpnInstanceIpVersionsRemoved) {
        neutronvpnUtils.updateVpnInstanceWithIpFamily(vpnId.getValue(), vpnInstanceIpVersionsToRemove, false);
    }
    clearFromVpnMaps(vpnId, routerId, null);
    try {
        checkAndPublishRouterDisassociatedFromVpnNotification(routerId, vpnId);
        LOG.debug("notification upon disassociation of router {} from VPN {} published", routerId.getValue(), vpnId.getValue());
    } catch (Exception e) {
        LOG.error("publishing of notification upon disassociation of router {} from VPN {} failed : ", routerId.getValue(), vpnId.getValue(), e);
    }
}
Also used : Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) Subnetmap(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.Subnetmap) TransactionCommitFailedException(org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException) ExecutionException(java.util.concurrent.ExecutionException) ReadFailedException(org.opendaylight.controller.md.sal.common.api.data.ReadFailedException) IpVersionChoice(org.opendaylight.netvirt.neutronvpn.api.enums.IpVersionChoice)

Example 50 with Subnetmap

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.Subnetmap in project netvirt by opendaylight.

the class NeutronvpnManager method updateVpnInternetForSubnet.

protected void updateVpnInternetForSubnet(Subnetmap sm, Uuid vpn, boolean isBeingAssociated) {
    LOG.debug("updateVpnInternetForSubnet: {} subnet {} with BGPVPN Internet {} ", isBeingAssociated ? "associating" : "dissociating", sm.getSubnetIp(), vpn.getValue());
    Uuid internalVpnId = sm.getVpnId();
    if (internalVpnId == null) {
        LOG.error("updateVpnInternetForSubnet: can not find Internal or BGPVPN Id for subnet {}, bailing out", sm.getId().getValue());
        return;
    }
    if (isBeingAssociated) {
        updateSubnetNode(sm.getId(), null, sm.getVpnId(), vpn);
    } else {
        updateSubnetNode(sm.getId(), null, sm.getVpnId(), null);
    }
    jobCoordinator.enqueueJob("VPN-" + vpn.getValue(), () -> singletonList(managedNewTransactionRunner.callWithNewWriteOnlyTransactionAndSubmit(wrtConfigTxn -> {
        if (isBeingAssociated) {
            updateVpnInterface(vpn, null, neutronvpnUtils.getNeutronPort(sm.getRouterInterfacePortId()), true, true, wrtConfigTxn);
        } else {
            removeVpnFromVpnInterface(vpn, neutronvpnUtils.getNeutronPort(sm.getRouterInterfacePortId()), wrtConfigTxn, sm);
        }
    })));
    // Check for ports on this subnet and update association of
    // corresponding vpn-interfaces to internet vpn
    List<Uuid> portList = sm.getPortList();
    if (portList != null) {
        for (Uuid port : portList) {
            LOG.debug("Updating vpn-interface for port {} isBeingAssociated {}", port.getValue(), isBeingAssociated);
            jobCoordinator.enqueueJob("PORT-" + port.getValue(), () -> {
                WriteTransaction wrtConfigTxn = dataBroker.newWriteOnlyTransaction();
                List<ListenableFuture<Void>> futures = new ArrayList<>();
                if (isBeingAssociated) {
                    updateVpnInterface(vpn, null, neutronvpnUtils.getNeutronPort(port), isBeingAssociated, false, wrtConfigTxn);
                } else {
                    removeVpnFromVpnInterface(vpn, neutronvpnUtils.getNeutronPort(port), wrtConfigTxn, sm);
                }
                futures.add(wrtConfigTxn.submit());
                return futures;
            });
        }
    }
}
Also used : WriteTransaction(org.opendaylight.controller.md.sal.binding.api.WriteTransaction) Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) ArrayList(java.util.ArrayList) ListenableFuture(com.google.common.util.concurrent.ListenableFuture)

Aggregations

Subnetmap (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.Subnetmap)50 Uuid (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid)47 ArrayList (java.util.ArrayList)20 ReadFailedException (org.opendaylight.controller.md.sal.common.api.data.ReadFailedException)15 SubnetmapKey (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.SubnetmapKey)12 TransactionCommitFailedException (org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException)11 WriteTransaction (org.opendaylight.controller.md.sal.binding.api.WriteTransaction)10 IpVersionChoice (org.opendaylight.netvirt.neutronvpn.api.enums.IpVersionChoice)9 Network (org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.networks.rev150712.networks.attributes.networks.Network)9 SubnetOpDataEntry (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.subnet.op.data.SubnetOpDataEntry)8 HashSet (java.util.HashSet)7 SubnetOpDataEntryKey (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.subnet.op.data.SubnetOpDataEntryKey)7 Subnetmaps (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.Subnetmaps)7 SubnetmapBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.SubnetmapBuilder)7 FixedIps (org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.port.attributes.FixedIps)7 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)5 SubnetOpDataEntryBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.subnet.op.data.SubnetOpDataEntryBuilder)5 Router (org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l3.rev150712.routers.attributes.routers.Router)5 BigInteger (java.math.BigInteger)4 HashMap (java.util.HashMap)4