Search in sources :

Example 81 with Router

use of org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l3.rev150712.routers.attributes.routers.Router in project netvirt by opendaylight.

the class NeutronvpnManager method checkAndPublishRouterAssociatedtoVpnNotification.

private void checkAndPublishRouterAssociatedtoVpnNotification(Uuid routerId, Uuid vpnId) throws InterruptedException {
    RouterAssociatedToVpn routerAssociatedToVpn = new RouterAssociatedToVpnBuilder().setRouterId(routerId).setVpnId(vpnId).build();
    LOG.info("publishing notification upon association of router to VPN");
    notificationPublishService.putNotification(routerAssociatedToVpn);
}
Also used : RouterAssociatedToVpn(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.RouterAssociatedToVpn) RouterAssociatedToVpnBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.RouterAssociatedToVpnBuilder)

Example 82 with Router

use of org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l3.rev150712.routers.attributes.routers.Router in project netvirt by opendaylight.

the class NeutronvpnManager method removeVpnFromVpnInterface.

protected void removeVpnFromVpnInterface(Uuid vpnId, Port port, WriteTransaction writeConfigTxn, Subnetmap sm) {
    if (vpnId == null || port == null) {
        return;
    }
    String infName = port.getUuid().getValue();
    InstanceIdentifier<VpnInterface> vpnIfIdentifier = NeutronvpnUtils.buildVpnInterfaceIdentifier(infName);
    try {
        Optional<VpnInterface> optionalVpnInterface = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, vpnIfIdentifier);
        if (optionalVpnInterface.isPresent()) {
            List<VpnInstanceNames> listVpn = optionalVpnInterface.get().getVpnInstanceNames();
            if (listVpn != null && VpnHelper.doesVpnInterfaceBelongToVpnInstance(vpnId.getValue(), listVpn)) {
                VpnHelper.removeVpnInterfaceVpnInstanceNamesFromList(vpnId.getValue(), listVpn);
            }
            VpnInterfaceBuilder vpnIfBuilder = new VpnInterfaceBuilder(optionalVpnInterface.get()).setVpnInstanceNames(listVpn);
            Adjacencies adjs = vpnIfBuilder.getAugmentation(Adjacencies.class);
            LOG.debug("Updating vpn interface {}", infName);
            List<Adjacency> adjacencyList = adjs != null ? adjs.getAdjacency() : new ArrayList<>();
            Iterator<Adjacency> adjacencyIter = adjacencyList.iterator();
            while (adjacencyIter.hasNext()) {
                Adjacency adjacency = adjacencyIter.next();
                if (adjacency.getAdjacencyType() == AdjacencyType.PrimaryAdjacency) {
                    continue;
                }
                String mipToQuery = adjacency.getIpAddress().split("/")[0];
                InstanceIdentifier<LearntVpnVipToPort> id = NeutronvpnUtils.buildLearntVpnVipToPortIdentifier(vpnId.getValue(), mipToQuery);
                Optional<LearntVpnVipToPort> optionalVpnVipToPort = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.OPERATIONAL, id);
                if (optionalVpnVipToPort.isPresent()) {
                    LOG.trace("Removing adjacencies from vpninterface {} upon dissociation of router {}", infName, vpnId);
                    if (listVpn == null || listVpn.isEmpty()) {
                        adjacencyIter.remove();
                    }
                    neutronvpnUtils.removeLearntVpnVipToPort(vpnId.getValue(), mipToQuery);
                    LOG.trace("Entry for fixedIP {} for port {} on VPN {} removed from VpnPortFixedIPToPortData", mipToQuery, infName, vpnId.getValue());
                }
            }
            List<FixedIps> ips = port.getFixedIps();
            for (FixedIps ip : ips) {
                String ipValue = String.valueOf(ip.getIpAddress().getValue());
                neutronvpnUtils.removeVpnPortFixedIpToPort(vpnId.getValue(), ipValue, writeConfigTxn);
            }
            if (listVpn == null || listVpn.isEmpty()) {
                if (sm != null && sm.getRouterId() != null) {
                    removeFromNeutronRouterInterfacesMap(sm.getRouterId(), port.getUuid().getValue());
                }
                deleteVpnInterface(port.getUuid().getValue(), null, /* vpn-id */
                writeConfigTxn);
            } else {
                writeConfigTxn.put(LogicalDatastoreType.CONFIGURATION, vpnIfIdentifier, vpnIfBuilder.build());
            }
        } else {
            LOG.info("removeVpnFromVpnInterface: VPN Interface {} not found", infName);
        }
    } catch (ReadFailedException ex) {
        LOG.error("Update of vpninterface {} failed", infName, ex);
    }
}
Also used : VpnInterfaceBuilder(org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.interfaces.VpnInterfaceBuilder) ReadFailedException(org.opendaylight.controller.md.sal.common.api.data.ReadFailedException) 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) VpnInstanceNames(org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.interfaces.vpn._interface.VpnInstanceNames) 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) FixedIps(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.port.attributes.FixedIps)

Example 83 with Router

use of org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l3.rev150712.routers.attributes.routers.Router in project netvirt by opendaylight.

the class NeutronvpnManager method updateVpnForSubnet.

private Subnetmap updateVpnForSubnet(Uuid oldVpnId, Uuid newVpnId, Uuid subnet, boolean isBeingAssociated) {
    LOG.debug("Moving subnet {} from oldVpn {} to newVpn {} ", subnet.getValue(), oldVpnId.getValue(), newVpnId.getValue());
    Uuid networkUuid = neutronvpnUtils.getSubnetmap(subnet).getNetworkId();
    Network network = neutronvpnUtils.getNeutronNetwork(networkUuid);
    boolean netIsExternal = NeutronvpnUtils.getIsExternal(network);
    Uuid vpnExtUuid = netIsExternal ? null : neutronvpnUtils.getInternetvpnUuidBoundToSubnetRouter(subnet);
    Subnetmap sn = updateSubnetNode(subnet, null, newVpnId, vpnExtUuid);
    if (sn == null) {
        LOG.error("Updating subnet {} with newVpn {} failed", subnet.getValue(), newVpnId.getValue());
        return sn;
    }
    // CAUTION:  Please DONOT make the router interface VPN Movement as an asynchronous commit again !
    try {
        WriteTransaction wrtConfigTxn = dataBroker.newWriteOnlyTransaction();
        updateVpnInterface(newVpnId, oldVpnId, neutronvpnUtils.getNeutronPort(sn.getRouterInterfacePortId()), isBeingAssociated, true, wrtConfigTxn);
        wrtConfigTxn.submit().checkedGet();
    } catch (TransactionCommitFailedException e) {
        LOG.error("Failed to update router interface {} in subnet {} from oldVpnId {} to newVpnId {}, returning", sn.getRouterInterfacePortId().getValue(), subnet.getValue(), oldVpnId, newVpnId);
        return sn;
    }
    // Check for ports on this subnet and update association of
    // corresponding vpn-interfaces to external vpn
    List<Uuid> portList = sn.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<>();
                updateVpnInterface(newVpnId, oldVpnId, neutronvpnUtils.getNeutronPort(port), isBeingAssociated, false, wrtConfigTxn);
                futures.add(wrtConfigTxn.submit());
                return futures;
            });
        }
    }
    return sn;
}
Also used : WriteTransaction(org.opendaylight.controller.md.sal.binding.api.WriteTransaction) 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) Network(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.networks.rev150712.networks.attributes.networks.Network) ArrayList(java.util.ArrayList) Subnetmap(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.Subnetmap) ListenableFuture(com.google.common.util.concurrent.ListenableFuture)

Example 84 with Router

use of org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l3.rev150712.routers.attributes.routers.Router in project netvirt by opendaylight.

the class NeutronvpnManager method handleNeutronRouterDeleted.

protected void handleNeutronRouterDeleted(Uuid routerId, List<Uuid> routerSubnetIds) {
    // check if the router is associated to some VPN
    Uuid vpnId = neutronvpnUtils.getVpnForRouter(routerId, true);
    Uuid internetVpnId = neutronvpnUtils.getInternetvpnUuidBoundToRouterId(routerId);
    if (vpnId != null) {
        // remove existing external vpn interfaces
        for (Uuid subnetId : routerSubnetIds) {
            removeSubnetFromVpn(vpnId, subnetId, internetVpnId);
        }
        clearFromVpnMaps(vpnId, routerId, null);
    } else {
        // remove existing internal vpn interfaces
        for (Uuid subnetId : routerSubnetIds) {
            removeSubnetFromVpn(routerId, subnetId, internetVpnId);
        }
    }
    // delete entire vpnMaps node for internal VPN
    deleteVpnMapsNode(routerId);
    // delete vpn-instance for internal VPN
    deleteVpnInstance(routerId);
}
Also used : Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid)

Example 85 with Router

use of org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l3.rev150712.routers.attributes.routers.Router in project netvirt by opendaylight.

the class NeutronvpnManager method checkAlarmExtraRoutes.

/**
 * This method setup or down an alarm about extra route fault.
 * When extra routes are configured, through a router, if the number of nexthops is greater than the number of
 * available RDs, then an alarm and an error is generated.<br>
 * <b>Be careful</b> the routeList could be changed.
 *
 * @param vpnId the vpnId of vpn to control.
 * @param routeList the list of router to check, it could be modified.
 */
private void checkAlarmExtraRoutes(Uuid vpnId, List<Routes> routeList) {
    if (!neutronvpnAlarm.isAlarmEnabled()) {
        LOG.debug("checkAlarmExtraRoutes is not enable for vpnId {} routeList {}", vpnId, routeList);
        return;
    }
    VpnInstance vpnInstance = neutronvpnUtils.getVpnInstance(dataBroker, vpnId);
    if (vpnInstance == null || routeList == null || routeList.isEmpty() || !neutronvpnAlarm.isAlarmEnabled()) {
        LOG.debug("checkAlarmExtraRoutes have args null as following : vpnId {} routeList {}", vpnId, routeList);
        return;
    }
    List<Routes> routesError = new ArrayList();
    for (Routes route : routeList) {
        // count  the number of nexthops for each same route.getDestingation().getValue()
        String destination = String.valueOf(route.getDestination().getValue());
        String nextHop = String.valueOf(route.getNexthop().getValue());
        List<String> nextHopList = new ArrayList();
        nextHopList.add(nextHop);
        int nbNextHops = 0;
        for (Routes routeTmp : routeList) {
            String routeDest = String.valueOf(routeTmp.getDestination().getValue());
            if (!destination.equals(routeDest)) {
                continue;
            }
            String routeNextH = String.valueOf(routeTmp.getNexthop().getValue());
            if (nextHop.equals(routeNextH)) {
                continue;
            }
            nbNextHops++;
            nextHopList.add(new String(routeTmp.getNexthop().getValue()));
        }
        final List<String> rdList = new ArrayList();
        if (vpnInstance.getIpv4Family() != null && vpnInstance.getIpv4Family().getRouteDistinguisher() != null) {
            vpnInstance.getIpv4Family().getRouteDistinguisher().stream().forEach(rd -> {
                if (rd != null) {
                    rdList.add(rd);
                }
            });
        }
        if (vpnInstance.getIpv6Family() != null && vpnInstance.getIpv6Family().getRouteDistinguisher() != null) {
            vpnInstance.getIpv6Family().getRouteDistinguisher().stream().forEach(rd -> {
                if (rd != null && !rdList.contains(rd)) {
                    rdList.add(rd);
                }
            });
        }
        // 1. VPN Instance Name
        String typeAlarm = "for vpnId: " + vpnId + " have exceeded next hops for prefixe";
        // 2. Router ID
        Uuid routerUuid = neutronvpnUtils.getRouterforVpn(vpnId);
        StringBuilder detailsAlarm = new StringBuilder("routerUuid: ");
        detailsAlarm.append(routerUuid == null ? vpnId.toString() : routerUuid.getValue());
        // 3. List of RDs associated with the VPN
        detailsAlarm.append(" List of RDs associated with the VPN: ");
        for (String s : rdList) {
            detailsAlarm.append(s);
            detailsAlarm.append(", ");
        }
        // 4. Prefix in question
        detailsAlarm.append(" for prefix: ");
        detailsAlarm.append(route.getDestination().getValue());
        // 5. List of NHs for the prefix
        detailsAlarm.append(" for nextHops: ");
        for (String s : nextHopList) {
            detailsAlarm.append(s);
            detailsAlarm.append(", ");
        }
        if (rdList.size() < nbNextHops) {
            neutronvpnAlarm.raiseNeutronvpnAlarm(typeAlarm, detailsAlarm.toString());
            LOG.error("there are too many next hops for prefixe in vpn {}", vpnId);
            routesError.add(route);
        } else {
            neutronvpnAlarm.clearNeutronvpnAlarm(typeAlarm, detailsAlarm.toString());
        }
    }
    // in routesError there are a few route raised in alarm, so they have not to be used
    routeList.removeAll(routesError);
}
Also used : Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) VpnInstance(org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.instances.VpnInstance) ArrayList(java.util.ArrayList) Routes(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l3.rev150712.l3.attributes.Routes)

Aggregations

Uuid (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid)93 BigInteger (java.math.BigInteger)60 ArrayList (java.util.ArrayList)46 ExecutionException (java.util.concurrent.ExecutionException)27 ReadFailedException (org.opendaylight.controller.md.sal.common.api.data.ReadFailedException)24 Routers (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.Routers)24 WriteTransaction (org.opendaylight.controller.md.sal.binding.api.WriteTransaction)23 TransactionCommitFailedException (org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException)21 ProviderTypes (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ProviderTypes)20 Subnetmap (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.Subnetmap)20 RpcResult (org.opendaylight.yangtools.yang.common.RpcResult)19 FlowEntity (org.opendaylight.genius.mdsalutil.FlowEntity)15 ExternalIps (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.routers.ExternalIps)14 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)13 UnknownHostException (java.net.UnknownHostException)12 Instruction (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.Instruction)12 InstructionGotoTable (org.opendaylight.genius.mdsalutil.instructions.InstructionGotoTable)11 RouterPorts (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.RouterPorts)11 List (java.util.List)10 InternalToExternalPortMap (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.router.ports.ports.InternalToExternalPortMap)10